I'm trying to do an exercise on vectors, and iterators. I tried searching on google but not much luck into my specific problem.
"Write a program using vectors and iterators that allows a user to maintain a list of his or her favorite games. The program should allow the user to list all game titles, add a game title, and remove a game title."
When I enter in y or Y it starts the loop over, but skips over my getline statement. Is it something still being stored in the input buffer? If so, how do I rectify that, and where is the source of the problem?
Here's the code so far:
Code:
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main(void)
{
vector<string> GAME_TITLE_VECTOR;
vector<string>::iterator i;
string GAME_TITLE;
char AGAIN = 'y';
cout << "\tWelcome to the favorite video game program!" << endl;
cout << "\tThis program stores your video game into what's called a vector\n\tand shows what you've entered in so far!" << endl;
cout << endl;
while ((AGAIN == 'y') || (AGAIN == 'Y'))
{
cout << "\n\nEnter one of your favorite video games!\n";
getline (cin,GAME_TITLE);
cout << "So far, you've entered:\n";
GAME_TITLE_VECTOR.push_back(GAME_TITLE);
for (i = GAME_TITLE_VECTOR.begin(); i != GAME_TITLE_VECTOR.end(); ++i)
{
cout << *i << endl;
}
cout << "\nWould you like to enter another title? ";
cin >> AGAIN;
}
system("PAUSE");
return EXIT_SUCCESS;
}