【发布时间】:2014-09-29 04:52:17
【问题描述】:
我最近刚开始使用 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 ??
}
}
非常感谢您的帮助。
【问题讨论】:
-
Tbh,我不确定你的问题是什么。您的评论已经显示了线索。
标签: c++ string file search counting