+ 1

Is the newline character only for outputting strings or is it just my syntax?

Total beginner, just going through the basic concepts. cout <<"Hello World\n;" // this gives a new line just fine int x=6; cout <<x\n; // this doesn't work, nor any variations of it I've tried int x=6 cout <<x<< endl; // this, of course, works just fine

2nd May 2017, 5:58 PM
Redbozo
3 Réponses
+ 3
'\n' is a char so you have to insert that into cout after x, so cout << x << '\n';
2nd May 2017, 6:02 PM
Bebida Roja
Bebida Roja - avatar
+ 1
or std::endl
2nd May 2017, 6:22 PM
Drauchris
Drauchris - avatar
0
What about a blank line? int x = 6; cout << x << '\n\n' ; cout <<"New line"; // outputs '62570New line' for some reason
2nd May 2017, 6:37 PM
Redbozo