cin.get(); being skipped in program

Hey guys so Im writting a text-based game and I wanted to split up the program and wait for some user responses so everything isn't spat out to the user at once leaving them too much to read and potentially turning them away from the game. My issue is that the compiler seems to be skipping one of the cin.get()'s I have

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
void createPlayer(Player *p) 
{ 
    std::string myName; 
    std::string myClass;
    
    std::cout << "Character Creation Screen:\n" 
              << "---------------------------\n"; 
    std::cout << "I apoligize adventurer, I have yet to get you name. What would you like to be called?\n"; 
    std::cout << "I would like to be called sir.";
    std::cin >> myName;  
    p->setID(myName); 
    std::cout << "\nAnd what are you most interested in becoming adventurer?\n"
              << "\n1. Warrior\n" 
              << "- Warriors focus on close combat with brutal and strong abilities while weilding with high HP.\n"
              << "Str: 10\nDef: 10\nRange: 2\nInt: 0\nHP: 250\n\n"; 
    std::cin.get(); 
    std::cout << "2. Mage\n" 
              << "- Mages focus on a medium range with agressive and powerful abilities while wielding low HP.\n"
              << "Str: 0\nDef: 3\nRange: 5\nInt: 10\nHP: 100\n\n"; 
    std::cin.get(); // wait for some response 
    std::cout << "3. Ranger\n"
              << "- Rangers focus on long range with quick and illusive abilities while wielding medium HP.\n"
              << "Str: 5\nDef: 5\nRange: 10\nInt: 0\nHP: 150\n"; 
    //std::cin >> myClass; 
    

    p = nullptr; 
} 


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
Character Creation Screen: 

I apologize adventurer, I have yet to get you name. What would you like to be called? 
I would like to be called sir. !![Waiting for player input here]!!
(I input my name "Brad") 

And what are you most interested in becoming adventurer? 

1. Warrior 
- Warriors focus on close combat with brutal and strong abilities while weilding with high HP 
Str: 10 
Def: 10 
Range: 2 
Int: 0 
HP: 250 
[ Suppose to wait for player input here but continues onto explaining the mage class.  
2. Mage 
ect.. 
[Waits for player input here on the second std::cin.get();]

Last edited on
It is possible that other input leaves characters in the stream. You may remove them using ignore:

http://en.cppreference.com/w/cpp/io/basic_istream/ignore

For numeric values the operator>> leave the entered new line charcter in the stream. See:

http://en.cppreference.com/w/cpp/io/basic_istream/operator_gtgt
Topic archived. No new replies allowed.