This situation is easy to encounter in the online written test: 输入一行整数,个数未知,整数之间用空格间隔
, in addition to string segmentation and extraction, the following simple methods can be used:
int main()
{
vector<int> inputs;
int tmp;
cin >> tmp;
inputs.push_back(tmp);
while (cin.get() != '\n') {
cin >> tmp;
inputs.push_back(tmp);
}
return 0;
}
Reference:
https://blog.csdn.net/lc013/article/details/77603310