What's the difference between cout <<"this "<<"is"<<"awesome" and cout << "this is awesome" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What's the difference between cout <<"this "<<"is"<<"awesome" and cout << "this is awesome"

I'm confused clear me out

20th Sep 2018, 11:50 AM
chidera
5 Answers
+ 6
The tutorials simply want to showcase the ability of being able to utilize the stream in such manner. There is no practical point at practicing the former instead of the latter.
20th Sep 2018, 12:05 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
Visually no differences but first version call 3 times << operator method and compiler allocate 3 constant string instead that one (like in second version)... Its not really important use one or other in usual contexts
20th Sep 2018, 12:48 PM
KrOW
KrOW - avatar
7th Aug 2019, 7:29 AM
Sonic
Sonic - avatar
+ 1
It is good to know if you need variable output. int x; //complex calculation x = .... cout<<"You need "<<x<<" apples for your cake."<<endl;
20th Sep 2018, 12:38 PM
Matthias
Matthias - avatar
+ 1
After compilation: none, compiler generates the same code (or should). Before compilation: std::cout is a stream object. So technically the stream is edited (append) 3 times. When you learn file streams, it'll make more sense why it's done this way.
20th Sep 2018, 11:27 PM
non