🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
Getting String Input
in a text-only program in C++, how would i get a whole string of input. i know how to get a single character or integer
char a;
cin >> a;
but what would i do if i wanted to get a whole word or set of numbers without doing like
char a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
please help me, any info would be helpful thank you
If I only had a nickle for every problem I''ve had, I wouldn''t have anymore problems, but then I guess I wouldn''t have anymore nickles either...
I don''t have a C++ reference around right now. But I know there are several functions that can be used to read lines of input.
Try getline(char*, int, char) from the iostream.h library.
the char * is the string you want to read into, int defines the string length, and the last char is an optional delimiter char.
Try getline(char*, int, char) from the iostream.h library.
the char * is the string you want to read into, int defines the string length, and the last char is an optional delimiter char.
Have you tried getchar().
I can''t remember the specific syntax but you should be able to find it in any C or C++ reference book.
Best regards,
Sherman
I can''t remember the specific syntax but you should be able to find it in any C or C++ reference book.
Best regards,
Sherman
This would be possible, too:
(The chars that are > SIZE will be erased)
char s[SIZE];char *Buffer;cin >> Buffer;sprintf (s, Buffer);
(The chars that are > SIZE will be erased)
You can either use cin.read or cin.getline. Here is an example with cin.getline:
Edited by - Mike on 1/19/00 11:48:08 AM
void main(){ char buffer[ 80 ]; cout << "Enter a sentence: "; cin.getline( buffer, 80 );}
Edited by - Mike on 1/19/00 11:48:08 AM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement