zoukankan      html  css  js  c++  java
  • 读写文件

    1.读文件

    FILE *fp_in = NULL;
    fp_in = fopen("test.h264", "rb");
    if (!fp_in) 
    {
        printf("Could not open input stream
    ");
        return -1;
    }
    
    unsigned char *in_buffer;
    in_buffer = new unsigned char[4096 * 4];
    
    unsigned char *cur_ptr = NULL;
    int cur_size = 0;
    
    while (feof(fp_in) == 0)
    {
        cur_size = fread(in_buffer, 1, 4096 * 4, fp_in);
        if (cur_size == 0)
            break;
    
        cur_ptr = in_buffer;
    
        //input_stream_data(cur_ptr, cur_size) ;
    
        Sleep(10);
    }
    
    fclose(fp_in);
    
    delete[] in_buffer;
    in_buffer = NULL;

    2.写文件

    写文件主要为以下:

    FILE * outfile;
    outfile = fopen("test.h264", "wb" );
    if( outfile == NULL )
    {
        printf("fopen error");
    }   
    
    fwrite( cur_ptr, sizeof( unsigned char ), cur_size, outfile );
        
    fclose(outfile);

    结合1、2,读写文件一起:

    FILE *fp_in = NULL;
    fp_in = fopen("test.h264", "rb");
    if (!fp_in) 
    {
        printf("Could not open input stream
    ");
        return -1;
    }
    
    FILE * outfile;
    outfile = fopen("out.h264", "wb" );
    if( outfile == NULL )
    {
        printf("fopen error");
    } 
    
    unsigned char *in_buffer;
    in_buffer = new unsigned char[4096 * 4];
    
    unsigned char *cur_ptr = NULL;
    int cur_size = 0;
    
    while (feof(fp_in) == 0)
    {
        cur_size = fread(in_buffer, 1, 4096 * 4, fp_in);
        if (cur_size == 0)
            break;
    
        cur_ptr = in_buffer;
    
        fwrite( cur_ptr, sizeof( unsigned char ), cur_size, outfile );
    
        Sleep(10);
    }
    
    fclose(fp_in);
    fclose(outfile);
    
    delete[] in_buffer;
    in_buffer = NULL;
  • 相关阅读:
    MySQL的数据库,数据表,数据的操作
    数组函数
    字符串函数,时间函数,数学函数,数组
    PHP函数
    php类型的相关函数,运算符,条件判断,循环
    PHP数据类型
    vector中erase用法注意事项
    C++11 右值引用&&
    vector中find和find_if的用法 以后再遍历剁手!
    在cocos2d中添加自己的shader教程
  • 原文地址:https://www.cnblogs.com/betterwgo/p/7894644.html
Copyright © 2011-2022 走看看