これまでの私のコードは次のとおりです
int main()
{
string word;
int wordcount = 0;
cout << "Enter a word to be counted in a file: ";
cin >> word;
string s;
ifstream file ("Names.txt");
while (file >> s)
{
if(s == word)
++ wordcount;
}
int cnt = count( istream_iterator<string>(file), istream_iterator<string>(), word());
cout << cnt << endl;
}
ファイル Names.txt には、大量の単語と数字が含まれています。istream iterator が単語をカウントする方法はよくわかりませんが、いくつかの結果が得られました。現時点で唯一のエラーは
in function int main
error: no match for call to `(std::string) ()'
それは「int cnt」で始まる行で発生します。数時間試してみましたが、C++ にはあまり詳しくありません。余分な文字列を作成するか、単語文字列を何らかの方法で変更する必要があるようです。
助けていただければ幸いです!!