0
Please tell me about cout and cin completly with example
3 Respostas
+ 4
cout belongs to std::ostream and cin belongs to std::istream
(The reason why we can still call them w/o needing to use istream/ostream is because we are using <iostream> , which contains both of them)
If you have noticed, if you just removed 'using namespace std;' , you would need to call cout using 'std::cout<<....' and cin using 'std::cin>>...' .
+ 2
In C++ the function *cin>>var;* assigns to the variable var the value that the user types and enters while the function *cout<<"messagge"<<endl;* prints the message as output (cout) and starts a new line (endl). You can also print the content of a variable with *cout<<var;* or both message and a variable's content *cout<<"abc"<<var<<"def";*. If the value of 3 was assigned to var, the output would be *abc3def* and continues on the same line.
P.S. You can also use \n instead of <<endl like this: cout<<"blabla"<<endl; will produce the same output as cout<<"blabla\n";
Hope i helped out and code on :)
+ 1
simple explanation:
cin gets things from your keyboard to your program
cout gets things from your program to your screen
for example:
cin>>x
would take the input from the keyboard and save it to the variable named x
cout <<x
will take whatever value saved in x and prints it to screen
of course if you want the scientifically correct explainaion, the the ones before me did a very good job :)