码迷,mamicode.com
首页 > 其他好文 > 详细

读写文件

时间:2017-08-01 12:37:05      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:leo   namespace   return   sig   str   std   user   output   users   

C++读写文件

#include <opencv/cv.h>
#include <fstream>
#include <iostream>
#include <string>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>



using namespace std;
using namespace cv;



#define W 1280
#define H 720

#define size W*H*2
int main()
{
    unsigned char y1, y2, u, v;
      char *buffer = new  char[size];
    string inpath = "C:\\Users\\liufeng16\\Desktop\\测试\\UVUY\\yuv3_5";
    string outpath = "C:\\Users\\liufeng16\\Desktop\\测试\\UVUY\\yuv0_5_outliufeng";


    ifstream filein(inpath);
    ofstream fileout(outpath);//结果
    filein.read(buffer, size);
    fileout.write(buffer, size);
    for (int m = 0; m < W*H; m += 2)
    {
        u  = buffer[m * 2];
        y1 = buffer[m * 2 + 1];
        v  = buffer[m * 2 + 2];
        y2 = buffer[m * 2 + 3];
        fileout << y1;
        fileout << u;
        fileout << y2;
        fileout << v;

    }
    filein.close();
    fileout.close();
    return 0;
}

 

 

c读写文件

 

#include <windows.h>
#include <fstream>
#include <iostream>
#include <string>
#include <iomanip>//不要忘记包含此头文件
#include <stdio.h>
using namespace std;
int  main()
{

    char *InputPath = "C:\\Users\\liufeng16\\Desktop\\测试\\UVUY\\yuv3_5";
    char *OutputPath = "C:\\Users\\liufeng16\\Desktop\\测试\\UVUY\\yuv3_5.yuv";


    char *InputBuf = new  char[1280*720*2];
     char *OutputBuf = new  char[1280*720*2];

    FILE *fpin,*fpout;
    if( ( fpin = fopen(InputPath, "rb")) == NULL)
    {
        exit(0);
    }
    if ((fpout = fopen(OutputPath, "w+")) == NULL)
    {
        exit(0);
    }
    fread(InputBuf, 1, 1280 * 720 * 2, fpin);
    strcpy(OutputBuf, InputBuf);
    fwrite(InputBuf,1, 1280 * 720 * 2,fpout);
    //cout << InputBuf;
    fclose(fpin);
    fclose(fpout);
    return 0;

    
}

读写文件

标签:leo   namespace   return   sig   str   std   user   output   users   

原文地址:http://www.cnblogs.com/fengliu-/p/7267578.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!