<分区>
我最近刚开始使用 C++,很想知道如何计算文件中特定点之间的行数。我已经可以成功地找到我想开始计数的第一个点,但我不知道如何进一步。
这是我到目前为止得到的:
ifstream fin;
string line;
char* search = "Key:";
char* search2 = "Color:";
// Open the file.
fin.open(filename);
// Check if it was successful in opening the file.
if (fin.fail() == true)
{
return false;
}
// Read from the file and continue to read until the end of the file is reached.
while (getline(fin, line)) {
if (line.find(search, 0) != string::npos) {
//Start counting line ??
}
}
如有任何帮助,我们将不胜感激。