Hi!!! I would like to know the meaning or purpose of these

case '\t' and case '\n'?

Thank you.

Recommended Answers

All 2 Replies

Greetings.
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";
cout<<string1;
return 0;
}

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.