C++ 如何处理输入多行整数的问题
ringa_lee
ringa_lee 2017-04-17 14:42:19
0
2
569
ringa_lee
ringa_lee

ringa_lee

reply all(2)
阿神
#include <sstream>
#include <string>
#include <vector>

std::string line, num;
std::vector<std::vector<int>> v;
size_t linenum = 0;
while (getline(cin, line)) {
    std::istringstream iss(line);
    while (line >> num) {
        v.push_back(vector<int>());
        v[linenum].push_back(stoi(num));
    }
    ++linenum;
}

I just finished reading C++ primer, and this is probably the approach.

刘奇

You are doing a question on OJ. If it is OJ, the required input is actually different from what you understand. You can refer to this

http://blog.csdn.net/sxheliji...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template