Originally posted by help_me
At school I am taking a c++ class, and in school we use codewarrior for the mac. At home tho I use Dev c++ (much better than codewarrior).
My problem occurs when I try to input to strings right after each other:
cout << "\nPlayer 1, please enter your name: ";
gets(player_1);
cout << "\nPlayer 2, please enter your name: ";
gets(player_2);
cout << endl << player_1 << " you are X\n";
cout << endl << player_2 << " you are O\n\n";
In codewarrior this works fine, but in dev c++ the output looks like this:
Player 1, please enter your name:
Player 2, please enter your name: joe
you are X
joe you are O
Press any key to continue . . .
it skips inputting the first players name, any body know why? I really appreciate any help... got to finish this by m
onday
If you're studying C++, why not try using some functions from the C++ standard library?.
Code:
#include <string>
// ...
std::string player[2];
cout << "Player 1, enter your name: ";
std::getline(std::cin, player[0]);
cout << "\nPlayer 2, enter your name: ";
std::getline(std::cin, player[1]);