0
Is there a difference between "\n" and endl in C++?
Just finished the Conditionals and Loops Unit the challenge said that my first answer was incorrect despite appearing the exact same as the expected output. But when I removed the "\n" and added endl it said it was correct.
3 Réponses
+ 1
check again..
hope these helps to find difference..
but it's the same in output..
https://www.sololearn.com/discuss/1956685/?ref=app
https://www.sololearn.com/discuss/127013/?ref=app
https://www.sololearn.com/discuss/242949/?ref=app
https://www.sololearn.com/discuss/2971109/?ref=app
https://www.sololearn.com/discuss/36076/?ref=app
+ 1
Yes, that can happen! endl will flush to the console immedietly when executing. '\n' on the other hand leaves it to c++ when to flush to the console. That means that the first code might have had not displayed the output fast enough.
0
"\n" and endl work the same way. Are you sure you didn't make a mistake in the syntax?
For example:
cout<<endl;
cout<<"\n";
printf("\n");