Hi, I have the following problem:
I use "getch" to monitor keypresses and the I use "cin" to input a
string.
When I type in 'y', the 'y' character appears, so I need to hit backspace
before typing the string.
c = getch();
cin >> str;
Please help me!
Thanks in advance
voidstar 3 5334
On Wed, 21 Jul 2004 20:31:04 GMT, voidstar <vo******@tin.it> wrote: Hi, I have the following problem:
I use "getch" to monitor keypresses and the I use "cin" to input a string.
When I type in 'y', the 'y' character appears, so I need to hit backspace before typing the string.
c = getch(); cin >> str;
Please help me! Thanks in advance voidstar
getch is not part of standard C++, cin is part of standard C++. If you try
an mix the two then the results are going to be unpredictable. Basically
don't do it.
Standard C++ has no way of monitoring keypresses, so if you need to do
this then you should forget about using standard C++ for any console input
or output.
john
John Harrison wrote: On Wed, 21 Jul 2004 20:31:04 GMT, voidstar <vo******@tin.it> wrote:
Hi, I have the following problem:
I use "getch" to monitor keypresses and the I use "cin" to input a string.
When I type in 'y', the 'y' character appears, so I need to hit backspace before typing the string.
c = getch(); cin >> str;
Please help me! Thanks in advance voidstar
getch is not part of standard C++, cin is part of standard C++. If you try an mix the two then the results are going to be unpredictable. Basically don't do it.
Standard C++ has no way of monitoring keypresses, so if you need to do this then you should forget about using standard C++ for any console input or output.
john
All true, but I found that it is compiler dependant. For example, in
Borland's compiler:
ch = getch();
switch(ch){
//select stuff
}
cin >> string; //or even cin.getline(const char[], int)
after pressing a button to be used in the switch() statement, that char
would be placed at the beginning of the string's array. However, using
Bloodshed's Dev-C++ IDE, it seems to 'clear the buffer'. I have, however
heard of functions that do this. I think http://www.cplusplus.com, but
I'm not sure.
I believe you should do a "cin>>ws;"
the "ws" means white space and should clear the buffer after you do
the getch();
On Tue, 27 Jul 2004 01:17:24 GMT, Ash <fu******@nb.sympatico.ca>
wrote: John Harrison wrote: On Wed, 21 Jul 2004 20:31:04 GMT, voidstar <vo******@tin.it> wrote:
Hi, I have the following problem:
I use "getch" to monitor keypresses and the I use "cin" to input a string.
When I type in 'y', the 'y' character appears, so I need to hit backspace before typing the string.
c = getch(); cin >> str;
Please help me! Thanks in advance voidstar
getch is not part of standard C++, cin is part of standard C++. If you try an mix the two then the results are going to be unpredictable. Basically don't do it.
Standard C++ has no way of monitoring keypresses, so if you need to do this then you should forget about using standard C++ for any console input or output.
john All true, but I found that it is compiler dependant. For example, in Borland's compiler:
ch = getch(); switch(ch){ //select stuff } cin >> string; //or even cin.getline(const char[], int)
after pressing a button to be used in the switch() statement, that char would be placed at the beginning of the string's array. However, using Bloodshed's Dev-C++ IDE, it seems to 'clear the buffer'. I have, however heard of functions that do this. I think http://www.cplusplus.com, but I'm not sure. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Timothy Madden |
last post by:
Hello
Is my program legal and well formed:
class Data;
class SMax
{
class Data &Buffer;
public:
SMax(class Data &buffer)
|
by: Kyle Kolander |
last post by:
I posted this in response to a previous thread but have not gotten any
replies back... Hopefully someone has an answer?
From looking at sections 27.7.3.2 and 27.7.1.2 of the standard, it appears...
|
by: Larry |
last post by:
Hi my friends.
How can I read keyboard buffer by C++ ?
Best regards,
Larry
|
by: nx-2000 |
last post by:
I've got a very large C# forms app and now that its being used in
bigger environments we're getting a steady stream of "why does it do
this?" problems. The most nagging of which right now is that...
|
by: srikanth |
last post by:
help me out with the subject
|
by: Sree |
last post by:
Hello Friends,
i was trying to read the Keyboard typeahead buffer from BIOS
according to its address.
But i'm not able to get the data.
Please tell me how to do so.
void main()
{
char far...
|
by: ppravin88 |
last post by:
hi guys 'n' gals .. could anyone tell me the difference between
getch(); and getche();
and when and where should we use this function...
and also wat is the diff between return(); & return(0);...
|
by: nettleby |
last post by:
The Microsoft site has confused me on this issue:
http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/iisbook/c06_redirection.mspx?mfr=true
Says that:
"ASP automatically discards...
|
by: NaN |
last post by:
I've been trying to use _kbhit() but it didn't do what I thought it
would from books, "Detects whether a keypress is available for reading."
Herbert Schildt says,
"If the user has pressed a key,...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |