Code:
int main()
{
vector<int> ratings(5);
for(int i=0; i<5; i++)
{
cout<< "enter rating:";
cin >> ratings[i]; // last '\n' is stored on the buffer
}
for(i=0; i<5; i++)
{
cout<< ratings[i];
/*Start to out put first item,
then '\n' stored in the buffer is passed to the
next statement cin.get() */
cin.get(); //received the '\n' from buffer at the second looping
//the loops works normally from the third item.
}
}
As I explained, the '\n' is stored in buffer result from the last inputting the last item for the vector. Try to ignore the '\n' at the end of the first loop. It will ignore that '\n' when the next cin.get() is called.
Code:
int main()
{
vector<int> ratings(5);
for(int i=0; i<5; i++)
{
cout<< "enter rating:";
cin >> ratings[i]; // last '\n' is stored on the buffer
}
cin.ignore(1000,'\n'); //ignore the last enter
for(i=0; i<5; i++)
{
cout<< ratings[i];
cin.get();
}