Inputting a two words.

Can someone please tell me what i am doing wrong here.
when i changed cin>>stuinfo[i].name to getline(cin,stuinfo[i].name);. it's skipping the getline(cin,stuinfo[i].name); the second time in the for loop.
basically the input i'm getting right now is

Input student name: sfas asdf
Input test score 1 : 32
Input test score 2 : 32
Input test score 3 : 32
Input test score 4 : 32
Input test score 5 : 32
Input student name: Input test score 1 :

so yeah, for some reason after the first time it completely disregarded the getline(cin,stuinfo[i].name);.


here's the code that i used.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
struct Score{
    string name;
    vector <int> tScore;
};
vector <Score >stuinfo(numStu);

void loadGrades(){
    int num;
    for(int i=0; i<numStu;i++){
        cout<<"Input student name: ";
        getline(cin,stuinfo[i].name);
        for(int j=0;j<5;j++){
            cout<<"Input test score "<<j+1<<" : ";
            cin>>num;
            stuinfo[i].tScore.push_back(num);
        }
    }
}
After the statement

cin>>num;

the new line symbol is in the input buffer so next getline reads an empty string.
ah i see the problem now, thanks a lot! :)
Topic archived. No new replies allowed.