如何将一行数据使用cin方法输入到vector容器中:
#include<iostream>
#include<vector>
using namespace std;
int main(){
int v;
vector<int> v1;
while(1){
cin>>v;
v1.push_back(v);
if(cin.get()=='\n')break;
}
for (vector<int>::iterator it = v1.begin(); it != v1.end(); it++) {
cout << *it << " " << endl;
}
system("pause");
return 0;
}
实例:
1 2 3
1
2
3