C++ console
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
You need to flush the output stream. If you use std::cout to print then try sending the flush manipulator. Something like this:
If you're just using the C functions then try calling fflush().
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);
Or you could do it the old fashioned way,
int a, character;
a = kbhit();
if ( a >= 1)
{
character = getch();
}
cout << char;
ace
int a, character;
a = kbhit();
if ( a >= 1)
{
character = getch();
}
cout << char;
ace
Uh...on VC++ at least, you can do it with getch and without kbhit. I don't know if you can with other compilers.
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.
Quote:Original post by ace_lovegrove
if ( a >= 1)
{
character = getch();
}
is getch() in iostream or do you need to include another header?
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
getch() is in conio.h and it is a non-standard function.
use getchar() from stdio.h instead.
use getchar() from stdio.h instead.
getch() is in conio.h
EDIT: is getchar() exactly equivalent? cool, but if your in c++ it should be cstdio (no .h)
EDIT: is getchar() exactly equivalent? cool, but if your in c++ it should be cstdio (no .h)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement