How to register keyboard input?

Hi there. Right now I am trying to make a text based adventure, but I do not know how to register input. Most of my somewhat basic skill relates to mathematics, loops, etc. and other more used things in C++. But right now I need to register input from a keyboard.


thanks!
Last edited on
Use cin>>.If u know about data file handling cin is an input stream object that reads output from keyboard.>> is a stream operator eg:-
1
2
3
4
int a;
cout<<"enter a number:"
cin>>a;   // copy the value (entered through keyboard) to a variable a

if tis is what u want
Since this is a text-based adventure, getline(cin, MyString); would probably be a better choice since it allows you to stream input with spaces and discards that extra newline character.

Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int main(int argc, char **argv){
   MagicInitializer();
   std::string User_Input = "";
   bool keep_playing = true;
   
   std::cout << "Welcome to my magical game.\n";
   do{
      std::cout << "Now what?" << std::endl;
      std::getline(std::cin, User_Input);
         //Super amazing function that determines output and modifies
         //keep_playing via reference.
      Magical_Input_Processor(User_Input, keep_playing);
   }while(keep_playing);
   Destroy_Magical_Traces();
   return 0;
}
Last edited on
Topic archived. No new replies allowed.