Problem with string and cin

I want the user to be able to have a two word team name but it skips the first team name and goes to the second team and works fine.

1
2
3
4
5
6
7
8
9
10
11
12
     cout<<"Enter team Names\n"<<endl;
     for(int i=0; i<numTeams; i++)
     {
       teams2.push_back(team());
       cout<<"Team "<<i+1<<" : "; 
       delay(40000);
       getline(cin, name); //problem is here
       teams2[i].name = name;
       outStream<<teams2[i].name<<endl;
     }
     cout<<endl;
     outStream.close(); //Team names have been saved 
alright I figured that out i had to put a dummy string to clear the white space and it works but now it skips the first word when I output

1
2
3
4
5
6
7
8
9
10
11
12
13
     cout<<"Enter team Names\n"<<endl;
     for(int i=0; i<numTeams; i++)
     {
       teams2.push_back(team());
       cout<<"Team "<<i+1<<" : "; 
       delay(40000);
       cin>>dummy;
       getline(cin, name); //problem is here
       teams2[i].name = name;
       outStream<<teams2[i].name<<endl;
     }
     cout<<endl;
     outStream.close(); //Team names have been saved 
I got rid of the cin>>dummy; and put a cin.ignore outside the for loop
#include <string>
#include <iostream>
using namespace std ;

int main()
{
string name ;

cout << "Please enter your full name: ";
cin >> name ;

cout << "Welcome " << name << endl ;

cout << "Please re-enter your full name: " ;

// Uncomment the next line to correct this program.
cin.ignore( 256, '\n' );
getline( cin, name ) ;

cout << "Thanks, " << name << endl ;

return 0 ;
}
@cbasic88 why did you use
 
cin.ignore( 256, '\n' ); 


here?

thanks
Topic archived. No new replies allowed.