|
-
Aug 3rd, 2002, 11:03 PM
#1
Thread Starter
Lively Member
reading text into a character array
How can you read in a name of a person into a character array without entering a single letter at a time?
-
Aug 4th, 2002, 01:58 AM
#2
PowerPoster
I didn't get it.
Can't you just use cin with the array name?
PHP Code:
char name[20];
cin>>name;
-
Aug 4th, 2002, 08:02 AM
#3
Member
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
-
Aug 4th, 2002, 08:14 AM
#4
Monday Morning Lunatic
Or why not be safer for people with long names?
Code:
string name;
getline(cin, name);
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|