13 Years
Discussion Span
Last Post by basementcoder

Erm, I'm not sure.
But generally, '\t' should be if the character is a constant TAB,
and the '\n' should be if the character is a constant NEWLINE. ;)


shouldn't this be in the C/C++ forum? :rolleyes:

Also, this is true, \t - Horizontal Tab, and \n - New Line (Line Carriage, i.e. the return or enter key). These are used in output and input. Output - If you want to add indentation and such you would use a horizontal tab, and if you wanted to put two sentences on different lines you could use \n between them to add a line break.

You can also use them in the function cin.getline which is included in the iostream.h header file. Syntax: cin.getline(variable, max_length, terminating_character). So, if you wanted a user to input a sentence, and you only wanted to store the text the user input untill they hit enter then this would suffice:

#include <iostream.h>

int main()
char string1[100];
cin.getline(string1, 100, '\n');
cout<<"The text you entered was:\n";
return 0;

Notice the use of \n inside of string and character marks. It cannot be used outside of these.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.