• c++ 读写txt方法


    写:

    #include<fstream>

    std::ofstream fout;
     fout.open("output.txt"); 
     fout <<"test content";

    读:

    FILE *fp=NULL;
       //得到csv文件中所有的字符
       fp = fopen("C:\UDS\config\input.txt","rb");
       char c = fgetc(fp);
       char* fp_base = fp->_base;

    //通过换行符分割成一个数组
     char* vectLines=strtok(const_cast<char*>( fp_base.GetText()), " ");
     while( vectLines != NULL ) 
     { 
      vectLines = strtok( NULL, " "); 
     }

      fclose(fp);

    注意这个读文件的方法有个缺点:文件大小有限制,貌似是4000多个字符,可以通过以下方法去解决:

    FILE *fp=NULL;
       fp = fopen("input.txt","rb");
       char c = fgetc(fp);

    while("判断c是有效字符")

    {

    //将读到的字符写入一个数组

    }
       char* fp_base = fp->_base;

    //通过换行符分割成一个数组
     char* vectLines=strtok(const_cast<char*>( fp_base.GetText()), " ");
     while( vectLines != NULL ) 
     { 
      vectLines = strtok( NULL, " "); 
     }

      fclose(fp);

    #include <fstream>  

    #include <string>  

    #include <iostream>  

    using namespace std;  

      

    int main()  

    {  

        ifstream in("1.txt");  

        string filename;  

        string line;  

      

        if(in) // 有该文件  

        {  

            while (getline (in, line)) // line中不包括每行的换行符  

            {   

                cout << line << endl;  

            }  

        }  

        else // 没有该文件  

        {  

            cout <<"no such file" << endl;  

        }  

      

        return 0;  

    }  

  • 相关阅读:
    include与php://input执行任意命令
    php Session反序列化漏洞
    php代码审计-file_get_contents()&file_put_contents()
    php代码审计-用户名和密码分开检验
    php -- get_magic_quotes_gpc()函数
    md5(“ffifdyop“,true)
    php弱类型相关
    BurpWeb安全学院之XXE
    ICMP隐藏通信隧道技术
    BurpWeb安全学院之敏感信息泄露
  • 原文地址:https://www.cnblogs.com/whiteIcrow/p/3553941.html
Copyright © 2020-2023  润新知