Can I use gets on C++?

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
Wei-Ming Chen
Experienced poster
Posts: 122
Joined: Sun Nov 13, 2005 10:25 am
Location: Taiwan

Can I use gets on C++?

Post by Wei-Ming Chen » Wed Feb 01, 2006 1:45 pm

Can I use gets or getchar on C++?
If can't, what can I use to instead?

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf » Wed Feb 01, 2006 2:16 pm

Yes, you can use gets() and getchar().
In fact, you can use anything that's in ANSI C.

Wei-Ming Chen
Experienced poster
Posts: 122
Joined: Sun Nov 13, 2005 10:25 am
Location: Taiwan

Post by Wei-Ming Chen » Wed Feb 01, 2006 3:02 pm

But I got compile error :-?

By the way
I wrote

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

is it wrong?

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf » Wed Feb 01, 2006 3:07 pm

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);

Wei-Ming Chen
Experienced poster
Posts: 122
Joined: Sun Nov 13, 2005 10:25 am
Location: Taiwan

Post by Wei-Ming Chen » Thu Feb 02, 2006 4:25 pm

Thanks for help. :)

Post Reply

Return to “C++”