By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

problem on getchar()...

P: n/a
Hi,
I've wrote a simple c++ program without graphic interface;
Now, if I build it with Visual Studio function getchar() works in a
way;
if I build it with Dev-C++ function getchar() works in another way.
Why?

Then, another question:

Is there a specific function to exit program pressing any button?
I've tried this with getchar() function, but after I press a button, I
must press Enter too.

Thank you.
MargNat

Sep 18 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
MargNat <ma*****@cashette.comwrote:
Hi,
I've wrote a simple c++ program without graphic interface;
Now, if I build it with Visual Studio function getchar() works in a
way;
if I build it with Dev-C++ function getchar() works in another way.
Why?

Then, another question:

Is there a specific function to exit program pressing any button?
I've tried this with getchar() function, but after I press a button, I
must press Enter too.
If I want the user to press Enter, then I do:

std::string trash;
std::getline(std::cin, trash);

Of course, this requires #include <string>. It only requires the user
to press Enter, and does not require pressing another key before it.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Sep 18 '06 #2

P: n/a
MargNat wrote:
Hi,
I've wrote a simple c++ program without graphic interface;
Now, if I build it with Visual Studio function getchar() works in a
way;
if I build it with Dev-C++ function getchar() works in another way.
Why?
Why what? You haven't shown any code or told us what "a way" and
"another way" mean. The crystal ball is in the shop this week.


Brian
Sep 18 '06 #3

P: n/a
MargNat <ma*****@cashette.comwrote:
>I've wrote a simple c++ program without graphic interface;
Now, if I build it with Visual Studio function getchar() works in a
way;
if I build it with Dev-C++ function getchar() works in another way.
Why?
getchar() is a macro rather than a function. This means there
is more likely to be inconsistent behavior, depending on how
you call it and depending on your system. Try using fgetc()
instead.

Steve
Sep 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.