How do I read long lines from a text file in C++?

前端 未结 3 1747
轻奢々
轻奢々 2020-12-19 05:12

I am using the following code for reading lines from a text-file. What is the best method for handling the case where the line is greater than the limit SIZE_MAX_LINE?

3条回答
  •  被撕碎了的回忆
    2020-12-19 05:45

    Since you're using C++ and iostream already, why not use std::string's getline function?

    std::string acLine;
    while(xInFile){
        std::getline(xInFile, acLine);
        // etc.
    }
    

    And, use xInFile.good() to ensure eofbit and badbit and failbit are not set.

提交回复
热议问题