首頁  >  問答  >  主體

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

ringa_leeringa_lee2713 天前502

全部回覆(2)我來回復

  • 阿神

    阿神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;
    }

    我剛看完C++ primer,大概是這樣的做法吧。

    回覆
    0
  • 怪我咯

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

    你這個是做OJ上的題吧,如果是OJ的話,其實要求輸入跟你理解的並不一樣, 可以參考一下這個

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

    回覆
    0
  • 取消回覆