+ 1
What's the difference between cout <<"this "<<"is"<<"awesome" and cout << "this is awesome"
I'm confused clear me out
7 Respuestas
+ 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.
+ 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
+ 2
Duplicate from the future:
https://www.sololearn.com/Discuss/1919968/?ref=app
+ 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;
+ 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.