I have a basic system of entering names to be randomly placed against each other. But i am having a problem with the first name. It is entering a blank for the first person and just moving onto the next
In the file it goes
1 2 3
1
2 Name
3 name
and so on
And when it asks you to enter the name it askes like
1 2
Enter 1st players name : Enter 2nd players name : (Name)
Enter 3rd players name : (Name)
Insted of
1 2
Enter 1st players name : (Name)
Enter 2nd players name : (Name)
I have a similar problem in my program - I just played around, and when I placed an additional getline right before my loop, as well as where it originally was - The problem was eliminated.
getline (cin, input);
For example:
In my new files it started with a empty line then the first line i entered, etc... After this change, my first line was not a empty line, but the first line i entered.
New Code that works without skipping 1:
1 2 3 4 5 6 7 8 9 10
getline (cin, input);
while (true) {
getline (cin, input);
if (input == "quit++")
break;
File << input << "\n";
}
File.close();
cout << " " << endl;
cout << "Your file has been saved." << endl;
Old code that skipped 1:
1 2 3 4 5 6 7 8 9
while (true) {
getline (cin, input);
if (input == "quit++")
break;
File << input << "\n";
}
File.close();
cout << " " << endl;
cout << "Your file has been saved." << endl;
Thanks it worked great. This took me like 2 day to try and find out on my own before i asked on here. I used the second option because it just looks better :)