Lesson 9: C-strings and '\n'
Here's a link to the tutorial: C Strings - C Tutorial - Cprogramming.com
I'm a little confused on this part of the tutorial:
Code:
#include <iostream>
using namespace std;
int main()
{
char string[256]; // A nice long string
cout<<"Please enter a long string: ";
cin.getline ( string, 256, '\n' ); // Input goes into string
cout<<"Your long string was: "<< string <<endl;
cin.get();
}
Quote:
Remember that you are actually passing the address of the array when you pass string because arrays do not require an address operator (&) to be used to pass their address. Other than that, you could make '\n' any character you want (make sure to enclose it with single quotes to inform the compiler of its character status) to have the getline terminate on that character.
I thought '\n' was something to put on the end of a line of coding to take it to the next line, simply for tidiness?
If I substitute '\n' for '\b', shouldn't the getline terminate at the point I type in b?
Code:
#include <iostream>
using namespace std;
int main()
{
char string[256]; // A nice long string
cout<<"Please enter a long string: ";
cin.getline ( string, 256, '\b' ); // Input goes into string
cout<<"Your long string was: "<< string <<endl;
cin.get();
}
Thanks for any help.