Why is there no speech marks in between each word when you are putting each word on its own line.? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is there no speech marks in between each word when you are putting each word on its own line.?

Original: cout << " Hello \n world! \n I \n love \n programming!"; Why doesn't this work as : cout << " Hello" \n "world!" \n "I" \n "love" \n "programming!";

5th Apr 2019, 6:51 PM
Anton Fleary
Anton Fleary - avatar
2 Answers
+ 4
Because \n is an ASCII symbol just like "A" or "@" and not a part of the programming language. Even if you want to cout nothing but a single line break \n, you need to put it in quotation marks: cout << "\n"; cout << "line one\nline two"; will output: line one line two endl is part of the programming language and not an ASCII symbol. That's why you have to interrupt the string every time you want to use endl and must not put it in quotation marks: cout << "line one" << endl << "line two";
5th Apr 2019, 7:21 PM
Anna
Anna - avatar
+ 1
Thank you so much
5th Apr 2019, 7:22 PM
Anton Fleary
Anton Fleary - avatar