0

Here is very simple question. My code not work with space. How to make it work without "_". So I want to "Flappy bird" together getting output not like Flappy_bird which has wished outcome. And when I typed in "your items" example to type inside flappy bird then hit enter the Q then it gets "bird" move to the next line. So i've checked a lot but there is nothing I could find out information.

 //user to maintain a list of his or her favorite games.
//Write a program should allow the user to list all game titles, add a game title, and remove a game title.

  
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main () {
vector<string> inventory;
inventory.push_back("world of war");
inventory.push_back("Tetris");
inventory.push_back("Call of duty 2");
inventory.push_back("dota 2");

vector<string>::iterator myIterator;
vector<string>::const_iterator iter;

cout <<"Your items:\n";
for (iter = inventory.begin(); iter != inventory.end(); ++iter)
{
    cout << *iter << endl;
}

string addtitle = "";
cout << "\nAdd a game title, enter Q to quit:\n ";
while(addtitle != "Q") {

cin >> addtitle;
inventory.push_back(addtitle);
}
   inventory.pop_back();
    cout << "Your items:";
    for (iter = inventory.begin(); iter != inventory.end(); ++iter)
    {
        cout << *iter << endl;
    }

}

1 Answers1

0

use getline(cin,addtitle); instead of cin >> addtitle;

mad-hin
  • 131
  • 12