Input numbers in a vector in C++ without any limit.When user press enter instead of a number it should print all the numbers inputted till now.
vector <int> numbers;
vector <int>::iterator i;
int num;
while(cin>>num && isdigit(num))
numbers.push_back(num);
for(i=numbers.begin();i!=numbers.end();++i)
{
cout<<*i<<'\n';
}
I am doing this thing but as soon as user press enter after taking suppose n numbers it exits the program w/o going to the printing loop.
Aucun commentaire:
Enregistrer un commentaire