+ 2
What is the difference between cout<<1+2; and cout<<1+2<<endl;
5 Answers
+ 3
endl moves down to a new line before printing the next text
+ 3
the second thing will make a new line, sience endl mens end line. for example lets asume the first line of the code above as A and the secod as B, if you write A then B the result will be
33
but if you write B then A the result will be
3
3
+ 2
std::endl flushes the stream so everything gets printed
if you dont use it the stream gets flushed when his tie (in this case std::cin) is used or the programm ends
+ 1
endl instruction moves outputes to the next line.
you'll see that good writing two codes:
first
cout << 1+2 << 3+4;
second
cout << 1+2 << endl << 3+4;
+ 1
Thank you!!!