I am currently learning how to write a code that prompts the user to define how many players and rounds they want in a dice game, with the additional goal to output the results of both into a file. A couple of resources I have seen have suggested when defining the string variable, you want a secondary string for the sole purpose to "gobble newlines."
Here is the snippet of the code I was looking at:
int main()
{
int nPlayers, nRounds, score;
**string name, dummy;**
cout <<"Enter number of players: ";
cin >> nPlayers;
cout << "Enter number of rounds: ";
cin >> nRounds;
**getline (cin, dummy); // gobble up newline**
ofstream ofs ("scores.txt");
ofs << nPlayers << " " << nRounds << endl;
My question is based around the two lines denoted with double asterisks. Why the need to write a string like this?