64,647
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <list>
#include <string>
#include <fstream>
#include <algorithm>
using namespace std;
int MatchString( const string& str)
{
string s("this") ;
return (s == str);
}
int main(){
ifstream ifs("MyLog1.log");
char c;
string s;
list<string> ls;
s.clear();
if (!ifs.bad())
{
//Print the contents in the file.
//cout << ifs.rdbuf();
//cout << endl;
//this is what this is what
do
{
ifs.get(c);
if (c != ' ')
{
s.append(1, c);
}
else if(s != ""){
ls.push_back(s);
s.clear();
}
} while (!ifs.eof());
ifs.close();
}
//Print the result.
cout << count_if(ls.begin(), ls.end(), MatchString) << endl;
//2
system("pause");
return 0;
}
#include <iostream>
#include <list>
#include <string>
#include <fstream>
#include <algorithm>
using namespace std;
int MatchString( const string& str)
{
string s("this") ;
return (s == str);
}
int main(){
ifstream ifs("MyLog1.log");
char c;
string s;
list<string> ls;
s.clear();
if (!ifs.bad())
{
//Print the contents in the file.
cout << ifs.rdbuf();
cout << endl;
//this is what this is what
do
{
ifs.get(c);
if (c != ' ')
{
s.append(1, c);
}
else if(s != ""){
ls.push_back(s);
s.clear();
}
} while (!ifs.eof());
ifs.close();
}
//Print the result.
cout << count_if(ls.begin(), ls.end(), MatchString) << endl;
//2
system("pause");
return 0;
}