0

I've been reading this book but still not 100% clear on the concept. So, please pardon me for asking such a trivial question as my only intention is to learn the basis right and not spam with trivial and/or duplicate questions.

I checked for related questions, but couldn't find the answers to my questions.

So, here goes:

This is the code snippet that is being referred to:

//s1 and s2 are objects of the std::string class

cout << "s1 is \""
     << s1
     << "\"; s2 is \""
     << s2
     << '\"';

This is what the author has to say about it:

We now output these two string objects, using cout and operator <<, which the string class designers overloaded to handle string objects.

Now then, overloaded? Does he mean that it's being overloaded as to accept two different arguments (string objects - s1/s2 and string literals - the stuff in " ") and perform the same function? Is my understanding right? Is that all it's getting overloaded with?

Bazooka
  • 1
  • 4

1 Answers1

1

In very brief, the built-in << means to left-shift an integral type.

The standard library provides an overloaded version of <<, that when given a stream (cout) and a string (s1, etc) will properly print the string to the screen.

I do highly recommend picking up a book from the book list: The Definitive C++ Book Guide and List

Community
  • 1
  • 1
Mark B
  • 95,107
  • 10
  • 109
  • 188
  • Your answer clarifies everything. The link provided by R Sahu will be helpful but not the ideal response to the answer I was looking for. Thank you Mark B. – Bazooka Feb 17 '15 at 19:53
  • Can you provide me such a definitive book guide and list for Java as well, if possible? – Bazooka Feb 17 '15 at 19:53
  • I'm reading this C++ book by Dietel and Dietel. Is it bad? – Bazooka Feb 17 '15 at 19:57