Jump to content
  • Advertisement
Sign in to follow this  
Kaze

C++ console

This topic is 5057 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

in a C++ console on a windows system does anyone know how to get the chacter printed to the console right away insted of after enter is pushed im trying to create a way of being able to enter data to a console wile another threade wirtes to it, it will delet whats the user has writen then print what it wants and restores what was there originaly there from the user if anyone knows a better way to write to the console while a user is typeing without breaking up the message that would be appresheated

Share this post


Link to post
Share on other sites
Advertisement
You need to flush the output stream. If you use std::cout to print then try sending the flush manipulator. Something like this:
std::cout << "My number: " << myNum << std::flush;

If you're just using the C functions then try calling fflush().
fprint("My number: %d",myNum);
fflush(stdout);

Share this post


Link to post
Share on other sites
Or you could do it the old fashioned way,

int a, character;

a = kbhit();

if ( a >= 1)
{
character = getch();
}

cout << char;

ace

Share this post


Link to post
Share on other sites
Uh...on VC++ at least, you can do it with getch and without kbhit. I don't know if you can with other compilers.

Share this post


Link to post
Share on other sites
There was this Article on gamedev just a few days ago. It goes over alot with the console, but I don't think the article series is done, or it might be too much for what you want.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by ace_lovegrove
if ( a >= 1)
{
character = getch();
}


is getch() in iostream or do you need to include another header?

Share this post


Link to post
Share on other sites
for kbhit and getch it says error C2065: 'getch' : undeclared identifier but it knows the paramtes and list the function when i click list members, so it seems to knows the function exist but says it dosent when i try to compile

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!