zoukankan      html  css  js  c++  java
  • 61.C++文件操作实现硬盘检索

     1 #include <iostream>
     2 #include <fstream>
     3 #include <memory>
     4 #include <cstdlib>
     5 #include <string>
     6 #include <cstring>
     7 using namespace std;
     8 
     9 void main()
    10 {
    11     ifstream fin("F:\大数据\大数据相关数据\kaifang.txt");
    12     ofstream fout(R"(C:
    es.txt)");
    13     if (!fin || !fout)
    14     {
    15         cout << "文件打开失败" << endl;
    16         return;
    17     }
    18     //如果没有到文件末尾
    19     while (!fin.eof())
    20     {
    21         //C语言方式查找
    22         //char str[500];
    23         //fin.getline(str, 500);
    24         //char *p = strstr(str, "小王");
    25         //if (p != nullptr)
    26         //{
    27         //    //输出到屏幕
    28         //    cout << str << endl;
    29         //    //写入到文件
    30         //    fout << str << endl;
    31         //}
    32 
    33         //C++方式查找
    34         char strpos[500]{ 0 };
    35         //读取一行
    36         fin.getline(strpos, 500);
    37         string str = strpos;
    38         //从第0个位置开始查找
    39         int pos = str.find("小李",0);
    40         if (pos != -1)
    41         {
    42             cout << str << endl;
    43             fout << str << endl;
    44         }
    45     }
    46 
    47     fin.close();
    48     fout.close();
    49     cin.get();
    50 }
  • 相关阅读:
    数据结构——数据结构的起源和研究内容
    数据结构——学习数据结构的意义
    C++中动态内存申请的结果
    C++中函数异常规格的说明
    C++异常处理的深入理解
    NOIP 2012 Day2
    NOIP 2012 Day1
    NOIP 2011 Day2
    NOIP 2011 Day 1
    NOIP 2010
  • 原文地址:https://www.cnblogs.com/xiaochi/p/8567680.html
Copyright © 2011-2022 走看看