Home  >  Q&A  >  body text

C++ 如何处理输入多行整数的问题

ringa_leeringa_lee2713 days ago498

reply all(2)I'll reply

  • 阿神

    阿神2017-04-17 14:44:19

    #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.

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 14:44:19

    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...

    reply
    0
  • Cancelreply