对照这个需要理解字符指针比较字符串,今天看了答案,隔天写
貌似让我直接写成了string类的比较了。。。原文地址
#include<iostream>
#include<vector>
#include<sstream>
#include<fstream>
#include<cstdlib>
#include<list>
using namespace std;
bool Equal(string &a,string&b)
{
if(a==b)
return true;
else return false;
}
int main()
{
ifstream fin;
fin.open("source.cpp");
if(!fin){cerr<<"Open error..."<<endl;exit(1);}
string findword="main()";
string word;
int num=0;
while(fin>>word)
if(Equal(word,findword))num++;
cout<<findword<<"出现"<<num<<"次。。。"<<endl;
fin.close();
return 0;
}