0
Cin and Cout
What is the difference
5 Respuestas
+ 11
► cin stands for console input used when you need to take input from user on console screen. The extraction operator(>>) is used along with the object cin for reading inputs.
► cout stands for console output which means that something you want to show as output on console screen. The data needed to be displayed on the screen is inserted in the standard output stream (cout) using the insertion operator (<<).
► Example :
#include<iostream>
using namespace std;
int main() {
int number;
cout << "Enter any number : "; // This output statement is used to show the output, basically an instruction for entering the input
cin >> number; // This input statement is used to take input from the user and stores it in the variable number.
cout << "The number is : "<< number; // This output statement displays the number that is taken as input
return 0;
}
+ 9
To make you understand how these two are used in a program. cin is used to take input from the user while cout is used to display some information to the user. These two are the basic things which are used if you are making an interactive program in C++.
If you were confused by that example then you can refer this :
[For cin]
int number;
cin >> number;
This takes the integer input from the user. Here user can enter 2 or 100 or 85 or 49 or any integer value and that is stored in the variable number.
[For cout]
cout << "Hello World !!";
This display the text Hello World !! on the output display screen.
+ 5
Clara Maria Ionita
Please go through the C++ tutorial you started, everything is explained; and
Read the COMMENTS in the lessons you can find great examples and explanations.
➝ Remember to use 🔍SEARCH. . . bar to avoid from posting duplicate threads!
+ 1
what is the purpose of using both cin and cout in this specific example?
+ 1
Nova thank you so much