C ++でクラスの名前を表示するためにstrstrを使用しています。私のコードの問題は、この文字列を探すことです:
"class "
入力ファイル全体。したがって、結果は次のようになります。
The CLASS name is class locCounter
The CLASS name is class ";
2行目はそこにあるべきではありません。基本的には、以下のコードの7行目を表示していますが、そうではありません。
int locCounter::classCounter()
{
int count = 0;
ifstream theOtherFile ("loc2.cpp");
while (! theOtherFile.eof())
{
const char *one = "class ";
getline(theOtherFile, otherFileData);
const char *result = otherFileData.c_str();
while ((result = strstr(result, one)) != NULL)
{
cout << "The CLASS name is " << result << endl;
result++;
}
}
}
それ以外に、「クラス」という単語を見つけてからクラスの最後の中括弧に到達するまで、関数に行数のカウントを開始させる方法を考えています。
ありがとう。