Hi! This is my first post, so be gentle.. :D

I am learning CPP with a book called "Beginning C++ Game Programming", and I have run into a problem.

The book asks me to make a program were the user can enter his/hers favorite games, delete a game, and print the list.

I am using vectors and iterations, and I cant seem to get the run-time error I am getting.
The error window says: "Expression: (this->_Has_containter()",0)

Here's my code:

if(command == "2")
			string deleteGame;
			cout << "Enter name of game: " << endl;
			cin >> deleteGame;
			for(iter = gameList.begin(); iter != gameList.end(); ++iter)

iter is invalid after calling erase, so you can't legally increment it. You need to be more careful about how you obtain the next iterator:

for (iter = gameList.begin(); iter != gameList.end(); ) {
    if (*iter == deleteGame)
        iter = gameList.erase(iter);

Thanks alot..
I figured that I could just break function when the if-statement was true, and that worked..

Now when I want to add a game, I use the string type variable, but if the game is multiple words, I only get the first word. What type of variable do I have to use, to have multiple words entered?

string newGame;
			cout << "\nEnter name of game: " << endl;
			cin >> newGame;

>cin >> newGame;
The >> operator stops reading when it encounters whitespace. If you want to read up to a specified character, you can use the std::getline function:

std::getline ( std::cin, newGame );

There's a magic third argument that defaults to '\n', but you can change that if you have a different delimiter. A pipe, for example:

std::getline ( std::cin, newGame, '|' );
This article has been dead for over six months. Start a new discussion instead.