How can you read in a name of a person into a character array without entering a single letter at a time?
Printable View
How can you read in a name of a person into a character array without entering a single letter at a time?
I didn't get it.
Can't you just use cin with the array name?
PHP Code:char name[20];
cin>>name;
Example :
char name[20];
cin.get(name, 20, '\n');
cin.ignore(80,'\n');
what this does is get 19 characters from the stream or until it encounters the \n character, whichever comes first. Since the delimiter is left in the stream, cin.ignore() will ignore 80 chars or up to the \n
Or why not be safer for people with long names?Code:string name;
getline(cin, name);