what is it \n

Mar 1, 2009 at 2:25am

My beginer C++ programming book just started adding this to the sample programs with out an explaination.

Iv tried to understand what this is for \n but cant figure it out.

im taking an online course and the prof. scared everyone into not sharing for fear of "copying" each other so now no one will talk to each other about anything, hopefully can get some help here :)

thanks
Last edited on Mar 1, 2009 at 2:29am
Mar 1, 2009 at 2:49am
\n is a newline character.

 
cout << "hi\nthere\nbuddy";

would print:
1
2
3
hi
there
buddy
Mar 1, 2009 at 2:56am
THANKS!
no wonder I couldt figure it out. the book always put it at the end of the cout lines that never required any lines after

EX:

If (ans=='y' || ans== 'Y')
{
cout << "what model? ";
cin >> model;
cout << "the " model << " is a great machine.\n";
}


why would there be a return line for this? see why I couldnt figure it..
Thanks for your help!
Mar 1, 2009 at 3:00am
Yeah ive been in that situation before. I think the reason they do that is because it is so hard to tell when someone has copied code. There are only a few reasonable ways to solve the problems, as long as you don't leave a comment that says "created by so and so", there's not a lot they can do. Besides scare the students.

Anyway, '\n' is the newline character. When the newline character is output to the console, the console breaks a new line. Anytime you see a \ it is specia: \t makes a tab, \0 means end of string, \\ makes one of these \. That's just a few.
Mar 1, 2009 at 3:21am
Sad but true. Glad everyone is willing to help out on this forum.
Thanks for the extra thats awesome to know!

Topic archived. No new replies allowed.