cin is used to read data from the console. (read from keyboard)
cout is used to write data to the console. (output to screen)
Example:
cin >> x;
Reads a value from the console and stores it in the variable x.
cout << "Hello World";
Writes "Hello World" to the console.
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!";
return 0;
}
#include <iostream>
using namespace std;
int main() {
int x;
cout << "Enter a number: ";
cin >> x;
cout << "Square of " << x << " is " << x*x;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main() {
string name;
cout << "Enter your name: ";
cin >> name;
cout << "Welcome " << name;
return 0;
}
Example: Welcome John Doe, you are 25 years old.
Enter your age: 25