In C++, we use:
cout โค for Output (C-out = Console Output)cin โค for Input (C-in = Console Input)These come from the iostream header file.
coutWe 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).
cinWe 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.