Each time the user enters a new name, you write over the old file. This is because you are creating the file with the same again and again. Rather declare the ofstream myfile ("example2.txt") outside the do while loop and that should work.
The second option is, if you already have knowledge of arrays, is just to add all the names to an array and at the end just loop through the array outputting the information to the file but that would also require you to restructure your program.
Edit:: Also your option number two is only going to read the first line in the file, not sure if that was the intent or not.
If I were you I would make a new option for getting information while making option 1 for saving, or the other way around, just keep them separate, like I said it would require you to restructure your program a bit.
anyways for putting info into an array using your current system of if statements:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
string foo[25];
int i = 0; //Used to access elements in the array, remember arrays start at 0
if (option == 0 )
{
if (i < 25) //Used to keep from going over array size
{
cout << "Enter Info: ";
cin >> foo[i];
i++; //increment i by one so the next time it will store info in the next element
}
else
{
cout << "No More room" << endl;
}
}
Then for saving to a file you can use a for loop to iterate through the array storing all of the info into the text file at once
ex:
1 2 3 4 5 6
int size_of_array = sizeof(foo) / sizeof (foo[0]); //get the size of the array for the for loop
//you can just use the i from earlier in this program, just showing how to get the size for future reference
for (int j = 0; j < size_of_array; j++) // or j < i if you prefer in this program
{
file >> foo[j];
}