How to read in space-delimited information from a file in c++

后端 未结 2 1702
深忆病人
深忆病人 2021-01-21 09:09

In a text file I will have a line containing a series of numbers, with each number separated by a space. How would I read each of these numbers and store all of them in an arra

2条回答
  •  無奈伤痛
    2021-01-21 09:43

    std::ifstream file("filename");
    std::vector array;
    int number;
    while(file >> number) {
        array.push_back(number);
    }
    

提交回复
热议问题