《Thinking in c++ 》第二册 ————4_2

来源:互联网 发布:软件测试工作日志 编辑:程序博客网 时间:2024/06/05 17:13

//打开一个文件(文件名作为命令行的第一个参数),并搜索文件中单词集合中的任意一个单词(作为参数出现在命令行上)。每次读入一行并匹配,结果输入一个新文件中

 

#include <cassert>

#include <cstddef>

#include <fstream>

#include <sstream>

#include <string>

#include <iostream>

using namespace std;

 

size_t findLeck(string kk,const string& from){

return kk.find(from);

}

 

int main(int argc,char* argv[]){

assert(argc == 4);

ifstream in(argv[1]);

//ifstream in("wowbull.cpp");

assert(in);

    string one,two;

while(getline(in,two)){

if((two !="")&&(findLeck(two,argv[3]) != string::npos)){

one += two;

}

}

//ofstream out("www.cpp");

ofstream out(argv[2]);

assert(out);

out << one;

return 0;

}

原创粉丝点击