Session 01
Fundamentals

Data Types & I/O

Master the basics of C++, input/output streams, and understand how data is stored in memory. Essential first steps for any competitive programmer.

If video doesn't load, watch on Drive

Session Notes

Standard I/O: iostream

Console Output (cout)

The cout object is used for outputting data to the standard output device (usually your screen). It is buffered and type-safe.

// Example of formatting with iomanip
cout << right << setw(5) << 122;
cout << setw(5) << 78 << '\n';

// Basic Types
int num = 10;
string str = "Hello, CPP!";
cout << "Result: " << num << " - " << str << endl;

Console Input (cin)

Used for getting input from the user. Note that cin stops reading at whitespace (space, tab, newline).

Pro Tip: getline()

To read a full line of text including spaces, use getline(cin, str).

string str;
// Reads until space
cin >> str; 

// Reads whole line until enter
getline(cin, str);

// Reads until custom delimiter ('.')
getline(cin, str, '.');

Error & Logging

cerr (Unbuffered)

Outputs immediately. Best for critical errors.

clog (Buffered)

Stores in buffer first. Best for non-critical logging.

Data Types & Limits

Understanding the limits of data types is crucial in Competitive Programming to avoid Overflow and Underflow.

int
double
float
char
bool
long long
short
unsigned int

How to check limits?

Modern C++ (limits)
#include <limits>
cout << numeric_limits<int>::max();
Simpler (climits)
#include <climits>
cout << INT_MAX;