That's really the point. It is the same. It is just in a function instead of inline.
The point is now it is easier to reason about this section of the code. It has 1 parameter and two variables. It does one thing. You can test it and verify that it works. And then you can forget about it. You just know that if you need the user to enter in a certain number of games, you can call this function.
You have three pieces that could be moved into functions. If you did that, your main() might look something like this:
1 2 3 4 5 6 7
int main()
{
int numGames = getNumGames();
vector<string> games = getGames(numGames);
printGames(games);
return 0;
}
It is immediately clear what the program is doing. You can work on each function in isolation. And because main() is small, you are unlikely to forget that main() returns a value.
It is possible to ask the user to input game names without specifically asking for how many. (That way the user doesn't have to think them all through in his head first.)
vector <string> getGames()
{
vector <string> games;
cout << "Please enter the names of your favorite games, one per line.\n""Press ENTER twice to finish.\n> "
<< flush;
string game;
while (getline( game ) && !game.empty())
{
games.push_back( game );
cout << "> " << flush;
}
return games;
}