In C++, we use:

These come from the iostream header file.


๐Ÿ”ธ 1. OUTPUT using cout

We use cout to print something on the screen.


#include <iostream>
using namespace std;

int main() {
    cout << "Hello, Nikhil!" << endl;
    return 0;
}

โœ… Output:


Hello, Nikhil!

๐Ÿ“ << is the insertion operator โ†’ it sends data to the output stream (screen).

๐Ÿ“ endl means end the line (go to next line).


๐Ÿ”ธ 2. INPUT using cin

We use cin to take input from the user.


#include <iostream>
using namespace std;

int main() {
    int age;
    cout << "Enter your age: ";
    cin >> age;
    cout << "Your age is: " << age;
    return 0;
}

โœ… If user enters: 21

โœ… Output:


Enter your age: Your age is: 21

๐Ÿ“ >> is the extraction operator โ†’ it takes data from user and stores it in a variable.