Correct use of \n | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 5

Correct use of \n

The questions use new line like " cout << "Hello \n World"; Not sure if that would work on the computer. Shouldnt it be " cout << "Hello " << \n << "world!";

2nd Jul 2019, 3:44 AM
Johnny Cruz Martinez
Johnny Cruz Martinez - avatar
9 Respostas
+ 2
It will definitely work the correct way is \n has to be inside " " doesn't matter if it is in the middle of the sentence like cout<<"Hell\no world"; will print Hell o world
2nd Jul 2019, 1:39 PM
Vratika Nagda
Vratika Nagda - avatar
+ 6
The correct of \n is following cout << "Hello \n World"; In line cout << "Hello " << \n << "world!"; The problem is you have to pass "\n" with the double quotes. This line will work if you will put \n inside quotes. Like thisšŸ‘‡ cout << "Hello " << "\n "<< "world!";
2nd Jul 2019, 3:53 AM
Deepak Kumar
Deepak Kumar - avatar
+ 6
endl is another way to add a new line.
2nd Jul 2019, 5:00 AM
Sonic
Sonic - avatar
+ 3
These are known as EscapeSequences. ā€¢\t: It is used forHorizontal tab. ā€¢\n: It is used forNew line. ā€¢\b: It is used forBackspace. Hope it was helpful..!
2nd Jul 2019, 10:24 AM
Saurav Kashyap
Saurav Kashyap - avatar
+ 2
Yes it's best Sonic
2nd Jul 2019, 2:06 PM
Charan Leo25
Charan Leo25 - avatar
+ 2
both will work fine just remember to use single quotes while using escape sequence
3rd Jul 2019, 6:12 AM
Aditya
Aditya - avatar
+ 1
Using it inside the string (double quotes) is the correct way. There are other characters that are enterpretted too like this, all starting with the ā€œ\ā€ like ā€œ\tā€ for a tab. The ā€œ\ā€ is used to escape the string too for characters that would normally cause problems, like double quotes. cout << ā€œHe said \ā€Hello world\ā€ and others knew he was a programmerā€ << endl; This line prints quotes around ā€œHello worldā€ without breaking the string.
2nd Jul 2019, 3:13 PM
nk361
nk361 - avatar
+ 1
Both are correct šŸ™‚
3rd Jul 2019, 5:42 AM
Sanjay Kamath
Sanjay Kamath - avatar
0
Hay
2nd Jul 2019, 1:48 PM
Arif Marsmello