我有這個代碼來計算文本文件中發生模式的次數。C++腳本來計算髮生模式的次數
#include <iostream>
int main()
{
// std::cout << "Hello World!" << std::endl;
// return 0;
ifstream fin("my_data.txt"); //opening text file
int count=0;
char ch[20],c[20];
cout<<"Enter a word to count:";
gets(c);
while(fin)
{
fin>>ch;
if(strcmp(ch,c)==0)
count++;
}
cout<<"Occurrence="<<count<<"n";
fin.close(); //closing file
return 0;
}
然而,在測試中,我得到這個錯誤
10 2 C:\用戶\ 80977432 \文件\ C++ \ Untitled1.cpp [錯誤] 'ifstream的' 未在此範圍
聲明
嘗試'的std :: ifstream'。 – songyuanyao
http://en.cppreference.com/w/cpp/io/basic_ifstream/basic_ifstream – Danh