vForums Support Banner



 

Welcome Guest! Please Login or Register
vForums Support :: Programming & Coding :: Programming Discussion :: Question on _getch() - View Topic
Topic Rating: *****
Printable View
lordotaku
Guest
Question on _getch() (9th Mar 08 at 7:24pm UTC)
Hey everyone, I am working on a project in which a character moves about a room. (This is only console output with ASCII characters)

I already have the code which generates the room and the character set up, and am now currently working on my movement functions.

To retrieve the value of the key pressed for the movement, I am using _getch(), and then using that value for a switch statement to determine which move function to call (up, down, left, right).

However, do I need to clear the buffer after using the _getch()?
If so, how exactly could I clear it?
Thanks for any help in advance. {Smile}

Oh and I am coding in C++
Marc
vChat Developer
*****
I <3 Rossy

Posts: 3,388
Status: Offline
Gender: Male
Location: Ontario, Canada
Age: 32
Joined:  

Additional Groups:
Coding Team
***


Reputation: 40%  


pmwww
Re: Question on _getch() (9th Mar 08 at 11:46pm UTC)
Not sure about how to clear the buffer in C++, but I believe you do need to; otherwise the image will be drawn in the new place without removing where it was previously, causing a big line. {Wink}

rroll.to— Shorten a link, rickroll your friends.
lordotaku
Guest
Re: Question on _getch() (10th Mar 08 at 4:50am UTC)
Thanks for the help Marc {Smile}

Well, if the buffer needs to be cleared I know that endl will clear it, but this would add an unwanted new line.

Does anyone who codes in C++ no another way to do it?


EDIT:
Just in case anyone else had this question, I found out that you can just code cout << flush to clear the buffer.
Avtar
New Member
*

[Avatar]
Traffic. That's why I hate four wheels.

Posts: 10
Status: Offline
Gender: Male
Location: India
Age: 36
Joined:  
Reputation: 0%  


pmwwwaim
Re: Question on _getch() (21st Mar 08 at 10:17am UTC)
fflush();

That function will clear the buffer for you. endl; is used like '\n'. It doesn't clear the buffer, simply adds a newline. endl was basically an easier way to add a new line in C++ since people found using escape sequences an issue in C. {Smile}

Image
 Printable View

All times are GMT+0 :: The current time is 10:52am
Page generated in 2.6557 seconds
This Forum is Powered By vForums (v2.4)
Create a Forum for Free | Find Forums