a small bight of help
how do i change this to a nother key for example
the shift key
cout << "Press the enter key to exit";
cin.ignore(std::cin.rdbuf()->in_avail() + 1);
please answer
That method detects any input, but you won't see anything until the enter key is pressed because the console is line-buffered - your program doesn't actually see any input data until the return, so there's nothing simple you can do.
Why do you want to do this? It may be that what you're trying to do is inappropriate for a console app, or that you're trying to learn things "out of order" by worrying about small things like this before you've really got the fundamentals down - or both.
Why do you want to do this? It may be that what you're trying to do is inappropriate for a console app, or that you're trying to learn things "out of order" by worrying about small things like this before you've really got the fundamentals down - or both.
If I understand you correctly, this is one way to do it in Win32:
P.S.
You're going to have to include the Windows header.
Edit: Also, if you're looking to change the target-key to some character, then this would work too:
[Edited by - raz0r on March 7, 2006 12:07:25 PM]
int main(void){ std::cout << "Press the shift key to exit" << std::endl; while(!GetAsyncKeyState(VK_SHIFT)) Sleep(100); return int();}
P.S.
You're going to have to include the Windows header.
Edit: Also, if you're looking to change the target-key to some character, then this would work too:
//Codewhile(_getch() != '\r') //In this instance, this will break when enter is pressed Sleep(100);//Some more code
[Edited by - raz0r on March 7, 2006 12:07:25 PM]
it is just that when i run this program
// My own thing
#include <iostream>
using namespace std;
int main()
{
string leader;
string felling;
cout << "Type your name here: ";
cin >> leader;
cout << "\nHello " << leader << " how are you?: ";
cin >> felling;
cout << "\nWell that is " << felling << ".\n";
cout << "Press the enter key to exit";
cin.ignore(std::cin.rdbuf()->in_avail() + 1);
return 0;
}
it dosent show the whole program
this ocors in other instances aswell
can you help
// My own thing
#include <iostream>
using namespace std;
int main()
{
string leader;
string felling;
cout << "Type your name here: ";
cin >> leader;
cout << "\nHello " << leader << " how are you?: ";
cin >> felling;
cout << "\nWell that is " << felling << ".\n";
cout << "Press the enter key to exit";
cin.ignore(std::cin.rdbuf()->in_avail() + 1);
return 0;
}
it dosent show the whole program
this ocors in other instances aswell
can you help
Quote:Original post by RaPfA
it is just that when i run this program
// My own thing
#include <iostream>
using namespace std;
int main()
{
string leader;
string felling;
cout << "Type your name here: ";
cin >> leader;
cout << "\nHello " << leader << " how are you?: ";
cin >> felling;
cout << "\nWell that is " << felling << ".\n";
cout << "Press the enter key to exit";
cin.ignore(std::cin.rdbuf()->in_avail() + 1);
return 0;
}
it dosent show the whole program
this ocors in other instances aswell
can you help
What exactly do you mean? The code that you pasted looks okay to me...
The output should be something like this, atleast from what I can see:
Type your name here: raz0r
Hello raz0r how are you?: good
Well that is good.
Press the enter key to exit.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement