Help - Complete noob

Why is this code not working correctly

When i debug, i put in one word and it works fine but when entering two words as a 'Favorite game' it counts it as two strings, why?????????!!!!!

//Game which will list favourite games
//Chapter 4 exercise

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
const int GAMES = 5; //the max amount of games the person can enter
int num = 0;
vector<string> fav_games;
string favourite; // the game that the user enters
while (num<GAMES)
{
cout<<"Please enter one of your favourite games: \n";
cin>>favourite;
fav_games.push_back(favourite);
num++;
}
return 0;
}
use getline option
For cin the delimiter for strings is space. Every word will be treated as separate string.

To input strings with spaces use
1
2
3
char buff[256];

cin.getline( buff, 255 );

Topic archived. No new replies allowed.