64,282
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <fstream>
#include <strstream>
#include <string>
using namespace std;
int main(int argc, char* argv[]) {
ifstream in(argv[1], ios::binary);
in.seekg(0, ios::end);
long fileSize = in.tellg();
cout << "file size = " << fileSize << endl;
string line, sch(argv[2]);
int linecount = 0;
cout << sch << "\n";
in.seekg(0, ios::beg);
while(getline(in, line)) {
++linecount;
if(line.find(sch) != string::npos)
cout << linecount << ": "
<< line << endl;
}
in.close();
return 0;
}