- 从getline读取多行并存入二维vector:
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main() {
int row;
cin>>row;
vector<vector<int>> a(row);
cin.clear();
cin.sync();
string str;
int temp = 0;
bool flag = false;
for(int j = 0; j<row; j++) {
cin.sync();
getline(cin, str);
for (int i = 0; i != str.size(); ++i) {
if (isdigit(str[i])) {
temp =temp* 10 + (str[i] - 48);
flag = true;
}
else {
if(flag) {
a[j].push_back(temp);
temp = 0;
}
flag = false;
}
if (i == (str.size() - 1) && flag) {
a[j].push_back(temp);
}
}
temp = 0;
flag = false;
cin.sync();
}
for(auto c:a) {
for(auto d:c)
cout<<d<<" ";
cout<<endl;
}
return 0;
}