Page 1 of 1

Can I use gets on C++?

Posted: Wed Feb 01, 2006 1:45 pm
by Wei-Ming Chen
Can I use gets or getchar on C++?
If can't, what can I use to instead?

Posted: Wed Feb 01, 2006 2:16 pm
by mf
Yes, you can use gets() and getchar().
In fact, you can use anything that's in ANSI C.

Posted: Wed Feb 01, 2006 3:02 pm
by Wei-Ming Chen
But I got compile error :-?

By the way
I wrote

char x[200];
getline(cin,x);

is it wrong?

Posted: Wed Feb 01, 2006 3:07 pm
by mf
To use gets() and getchar() you have to include <stdio.h> or <cstdio>.

If il doesn't help, post your source code here.
char x[200];
getline(cin,x);

is it wrong?
I get a compile error with that with gcc. This code should be okay:
string x;
getline(cin, x);

Posted: Thu Feb 02, 2006 4:25 pm
by Wei-Ming Chen
Thanks for help. :)