0
Im very comfused
Whats the difference between cout << "This " << "is " << "awesome!"; and cout << "This is awesome!";
3 Antworten
+ 5
https://code.sololearn.com/cjHQRJUG5NTf/?ref=app
This code can tell some different
+ 5
In practical, there is no reason to do:
cout << "This " << "is " << "awesome!";
instead of
cout << "This is awesome!";
The content in the slides are just there to show you that it can be done. You may use it to print variables to a continuous sentence, e.g.
int x = 100;
cout << "I have " << x << " cookies in my jar";
+ 3
<< is an operator...it calls a function/method every time it is used (to handle types). Your first example makes 3 calls; the second makes 1. Realistically, the compiler will probably optimize it out, but it's still less efficient.
http://en.cppreference.com/w/cpp/io/basic_ostream/operator_ltlt
http://en.cppreference.com/w/cpp/string/basic_string/operator_ltltgtgt