Why ist like that [ cout << "Hello world! \n";] and not like that [cout << "Hello world!" \n; | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why ist like that [ cout << "Hello world! \n";] and not like that [cout << "Hello world!" \n;

3rd Jan 2017, 6:16 PM
sarhad ezio
sarhad ezio - avatar
5 Answers
+ 7
Because "\n" is outside quotes and considered as variable...
3rd Jan 2017, 6:17 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 6
You can do : cout<<"Hello world!"<<"\n";
3rd Jan 2017, 6:21 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 1
but (\n) is inside of quotes???
3rd Jan 2017, 6:20 PM
sarhad ezio
sarhad ezio - avatar
+ 1
Mmm.... its in quotes not like (endl) okay thanks
3rd Jan 2017, 6:28 PM
sarhad ezio
sarhad ezio - avatar
0
the backslash "\" is actually an escape sequence. it is used to print out special characters in a string. For example if you want to print out " instead of actually closing the tag, you can type \". and therefore that is why \n has to be within the double quotes because the back slash is specially for printing special characters :)
23rd Jan 2017, 3:46 PM
Furqaan Hafiz
Furqaan Hafiz - avatar