Can someone explain what are
and what are they used for.Code:cout and endl
Printable View
Can someone explain what are
and what are they used for.Code:cout and endl
In C++, I/O is done using streams. cout is a variable of type ofstream that is bound to the standard file stdout. This means, basically, that any output sent to cout appears on the console:
endl is actually a function, that adds a newline, then flushes the buffer. It's effectively:Code:cout << "Here is a string";
equals:Code:cout << "String" << endl;
There are also streams called cin (stdin), and cerr (stderr).Code:cout << "String" << "\n";
cout.flush();
endl makes the next thing added on a new lineCode:#include <iostream.h>
int main()
{
cout << "Hello" << endl;
cout << "World!" << endl;
cout << "\n";
cout << "OR without endl";
cout << "\n";
cout << "Hello";
cout << "World!";
return 0;
}
/n has the same effect except it has to be part of a string
cout displays text in a console window. It has to be followed by << and then the string
waits for the user to enter a value (in this case a long integer)Code:int decared_variable
cin >> declared_variable
I hope this helps,
Me.