• 文本中删除不含关键字符串的行


     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 }
    **************************************************************
    我喜欢程序员,他们单纯、固执、容易体会到成就感;面对困难,能够不休不眠;面对压力,能够迎接挑战。他们也会感到困惑与傍徨,但每个程序员的心中都有一个比尔盖茨或是乔布斯的梦想,用智慧把属于自己的事业开创。其实我是一个程序员
    [=.=]
  • 相关阅读:
    数组
    循环(二)
    循环——笔记
    C#基础(四)
    C#基础(三)
    安卓帮助文档
    增加线程异步发送消息的方法二(Runnable)
    增加线程异步发送消息的方法一(Thread)
    获取下拉框的值
    获取表中字段最大值,并且保存在前台页面中
  • 原文地址:https://www.cnblogs.com/kevinGaoblog/p/2598782.html
Copyright © 2020-2023  润新知