0

Im very comfused

Whats the difference between cout << "This " << "is " << "awesome!"; and cout << "This is awesome!";

27th Jun 2017, 3:37 AM
Megaterium
Megaterium - avatar
3 Antworten
+ 5
https://code.sololearn.com/cjHQRJUG5NTf/?ref=app This code can tell some different
27th Jun 2017, 3:47 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 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";
27th Jun 2017, 6:12 AM
Hatsy Rei
Hatsy Rei - avatar
+ 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
27th Jun 2017, 4:28 AM
Kirk Schafer
Kirk Schafer - avatar