Concatenating with cout
The second new feature of getinfo.cpp is combining four output statements into one. The iostream file defines the << operator so that you can combine (that is, concatenate) output as follows:
cout << "Now you have " << carrots << " carrots." << endl;
This allows you to combine string output and integer output in a single statement. The resulting output is the same as what the following code produces:
cout << "Now you have ";cout << carrots;cout << " carrots";cout << endl;
While you’re still in the mood for cout advice, you can also rewrite the concatenated version this way, spreading the single statement over four lines:
cout << "Now you have " << carrots << " carrots." << endl;
That’s because C++’s free format ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access