Notice that we can send endl to cout, even though it isn't a string.
Remember that cout can be given every standard type of data that there
is in C++, be it a string, a number, a character, or the special cursor-movers
(such as endl ). For instance, look at this use of cout :
int a; float b; a = 4; b = 52.2 cout << "Hey World, it's me. Again."; cout << endl; cout << "World, do you like the number "; cout << a; cout << " or "; cout << b; cout << " better?"; cout << endl;
Hopefully that was fairly easy to understand. However, please take a moment to
go through it slowly; Although it may seem too easy to waste time on,
Hey World, it's me. Again. World, do you like the number 4 or 52.2 better? Here's the cool part -- you don't have to put each of those pieces of the second line in different statements! You can combine them all by simply using << between the pieces of data. Here's an example of this trick:
cout << "Hey World, it's me. Again." << endl;
Neat, huh? The way this works is that the C++ compiler runs this in two steps.
First, it executes " int a; double b; a = 4; b = 52.2; cout << "Hey World, it's me. Again." << endl; cout << "World, do you like the number " << 4 << " or "; cout << 52.2 << " better?" << endl;
See how much easier that is? We hope you'll recognize that it's kind of like
Pascal's cout << "World, what's up?" << endl << endl << endl << endl << endl << endl; |