zoukankan      html  css  js  c++  java
  • 文本中删除不含关键字符串的行

     1 #include <string> 
     2 #include <fstream> 
     3 #include <iostream>
     4 
     5 using namespace std;
     6 
     7 const string sourceFile="source.txt";        //源文件路径
     8 const string resultFile="result.txt";        //结果文件路径
     9 const string keyStr="a";            //关键字符串
    10 
    11 int _tmain(int argc, _TCHAR* argv[])
    12 {
    13     string str;
    14     ifstream fin(sourceFile);
    15     ofstream fout(resultFile);
    16 
    17     if(fin.fail())
    18     {
    19         cout<<"source file open failed!";
    20         return 1;
    21     }
    22 
    23 
    24     while ( getline(fin,str))        //按行读取,
    25     {
    26         if( str.find(keyStr,0)!=string::npos )        //查找关键字符串,
    27             fout<<str<<"\n";
    28     }
    29 
    30     return 0;
    31 }
    **************************************************************
    我喜欢程序员,他们单纯、固执、容易体会到成就感;面对困难,能够不休不眠;面对压力,能够迎接挑战。他们也会感到困惑与傍徨,但每个程序员的心中都有一个比尔盖茨或是乔布斯的梦想,用智慧把属于自己的事业开创。其实我是一个程序员
    [=.=]
  • 相关阅读:
    nyoj58 最少步数
    oj2787 算24
    一位ACMer过来人的心得
    hdu递推公式水题
    nyoj20 吝啬的国度
    hdu1421 搬寝室
    全排列生成算法:next_permutation
    hdu2544 最短路
    poj1691 Painting A Board
    hdu1274 展开字符串
  • 原文地址:https://www.cnblogs.com/kevinGaoblog/p/2598782.html
Copyright © 2011-2022 走看看