我想阅读类似这样的txt文件的每一行
1190/2132 123/23123 45
我想阅读整行,然后将它们存储在三个单独的字符串中,以备将来用于构建树时使用。我现在正在使用fgets,但是在将其放入字符串时出现错误。我该怎么办?
最佳答案
试试这个:
std::string line;
while(std::getline(file, line))
{
std::stringstream linestream(line);
std::string word1, word2, word3;
line >> word1 >> word2 >> word3;
// Store words
}
关于c++ - 如何以某种模式读取C++中的一行并将其存储在字符串中?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3764545/