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...
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
_________________ Best regards, Sherman Chin Director Sherman3D (Malaysia) Sdn Bhd www.Sherman3D.com www.AlphaKimori.com
I believe the C library functions gets and scanf will both read a whole line of input.
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)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement