多行输入,分行读取输入
作者:
liyuliyu
,
2024-05-25 22:00:14
,
所有人可见
,
阅读 2
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
using namespace std;
int main() {
string line;
vector<vector<int>> all_numbers;
// 逐行读取输入
while (getline(cin, line)) {
istringstream iss(line);
vector<int> numbers;
int number;
// 逐个读取数字
while (iss >> number) {
numbers.push_back(number);
}
// 将这一行的数字存储到 all_numbers 中
all_numbers.push_back(numbers);
}
// 按照输入的样子分行输出
for (const auto& numbers : all_numbers) {
for (const int number : numbers) {
cout << number << " ";
}
cout << endl;
}
return 0;
}