C++ console

Started by
7 comments, last by Ademan555 19 years, 4 months ago
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
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);
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
Or you could do it the old fashioned way,

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.
http://edropple.com
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.
getch() is in conio.h

EDIT: is getchar() exactly equivalent? cool, but if your in c++ it should be cstdio (no .h)
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."

This topic is closed to new replies.

Advertisement