← C++ roadmap

Topic 1 of 27 · Beginner

Introduction & I/O

First program, namespaces, cin/cout and fast I/O.

Concept

C++ extends C with classes, templates, a rich standard library and stronger type safety, while staying close to the hardware.

std::cout prints and std::cin reads. using namespace std is fine in small programs but avoid it in headers.

For competitive programming, disable sync with C I/O for speed.

Code (C++20)

#include <iostream>
#include <string>

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    std::string name;
    int age;
    std::cin >> name >> age;
    std::cout << "Hi " << name << ", age " << age << '\n';
    return 0;
}

Remember

  • Prefer '\n' over std::endl (endl flushes).
  • C++ is mostly a superset of C.
  • Use std::string, not char arrays.

Interview questions

C vs C++?

C is procedural. C++ adds OOP, templates, references, exceptions, RAII and the STL.

endl vs \n?

Both end the line; endl also flushes the stream, which is slower in loops.

Practise C++ with the AI mentor

Lesson test

Take an 8-question test on “Introduction & I/O” — concepts, output prediction, bug spotting and interview questions.

Can't find a C++ topic you need for exams or placements? Request it and we'll add it.