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 »

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 »

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 »

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 »

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 »

Thanks for help. :)
Post Reply

Return to “C++”