我试图读取两个字母之间的文件的一部分:
a
//text goes here that im reading from
a
b
//second text goes here
b
我想学习如何在a和a之间读书, 和b和b。
答案 0 :(得分:1)
在下次发布之前再做一些研究(或者告诉我们你尝试了什么)。这次应该对你有所帮助:
#include <iostream>
#include <string>
#include <fstream>
int main()
{
std::fstream myFile("file.txt");
bool foundLetter=false;
std::string stringFromFile;
while (std::getline(myFile, stringFromFile))
{
if (foundLetter &&
stringFromFile != "a" &&
stringFromFile != "b")
{
std::cout << "Line between letters is: " << stringFromFile << std::endl;
}
if (stringFromFile == "a" ||
stringFromFile == "b")
{
foundLetter = true;
}
else
{
foundLetter = false;
}
}
system("pause");
return 1;
}