Posts: 12
Threads: 1
Joined: May 2006
How would I get input like you would use INKEY$ in basic? I've been programming qbasic for a while now and now I want to try to transition to C++, but I can't find much about this.
I would search to see if this has been asked before but I just found this forum and I don't know where the search feature is (if there is one)
lt;(im_an_alien)>
Posts: 508
Threads: 49
Joined: May 2002
Which version are you using?
Posts: 12
Threads: 1
Joined: May 2006
Version of what?
If you are asking what compiler I am using Dev-C++ 4.9.9.2 right now, although I plan to be possibly using a DOS version of Turbo C++ in the future
lt;(im_an_alien)>
Posts: 508
Threads: 49
Joined: May 2002
Edit: I was pretty far off. Read stylin's post below for the correct way.
Posts: 324
Threads: 12
Joined: Nov 2005
You're going to want to use C++ headers (no .h) and C++ functions if you're learning C++:
Code:
# include <iostream>
int main()
{
char ch = std::cin.get();
// or ...
std::cin.get(ch);
...
return 0;
}
Start here:
http://msdn2.microsoft.com/en-us/library/22z6066f.aspx (the easiest way to learn C++ is by buying [a] book[s]. Good luck!
stylin:
Posts: 12
Threads: 1
Joined: May 2006
I tried that, and I noticed that it seems to just do a cin and then take the first character. I made this little program to print the characters on the screen
Code:
# include <iostream>
using namespace std;
char ch;
int main()
{
cin.get(ch);
cout << ch;
system("PAUSE");
return 0;
}
ps i think this program might be Dev-Cpp only, not sure.
lt;(im_an_alien)>
Posts: 320
Threads: 24
Joined: Feb 2005
Quote:I tried that, and I noticed that it seems to just do a cin and then take the first character.
That's because you're only storing one character. Store more characters and you'll be able to enter more data.
Either that or use std:
tring.
.14159265358979323846264338327950288419716939937510582709445
Glarplesnarkleflibbertygibbertygarbethparkentalelelangathaffendoinkadonkeydingdonkaspamahedron.
Posts: 12
Threads: 1
Joined: May 2006
actually what I wanted to do was not have to press enter and return the key pressed
lt;(im_an_alien)>
Posts: 324
Threads: 12
Joined: Nov 2005
Do you want execution to wait until the user presses a key, or do you want to still be able to execute while checking for input?
stylin:
Posts: 12
Threads: 1
Joined: May 2006
either way, just want to be able to press a key and it does something
lt;(im_an_alien)>