cin and cout are objects.
cin is an object representing the input stream.
So you can have this statement:
cin >> number;
This will read from the inputstream, usually your keyboard, a number (if number is a int variable). and stores it in the variable.
cout is an object representing the output stream.
So you can have this statement:
cout << "Wouter" << endl;
Writes the string literal Wouter to screen and calls a function std::endl() that writes a "\n" to the output stream and flushes the stream. usually the outputstream, is your screen.
cin has another special property, when you use it for example to read a string into a character array variable, it searches in the input for whitespace, as soon as it finds whitespace, cin thinks its work is done, this is behaviour you should understand! see the next example:
char name[ArSize];
cin >> name;
if you type in: Janssen Wouter
cout << name;
will result in only outputing Janssen
even more worse
if the next statement is:
cin >> name2;
cin will have in its buffer the second name, in this case Wouter and puts it just in the variable name2.
Know this behaviour and protect yourself against it, I will explain how to if I know more!
Abonneren op:
Reacties posten (Atom)
Geen opmerkingen:
Een reactie posten