problem on getchar()...

M

MargNat

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
 
M

Marcus Kwok

MargNat said:
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.
 
D

Default User

MargNat said:
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
 
S

Steve Pope

MargNat said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top