c++ fstream用法


今天介紹一個復制 粘貼的函數,用fstream實現

#include "stdafx.h"
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    fstream in("a.jpg", ios_base::binary|ios_base::in);
    if (in.is_open())
    {
        fstream out("F:/1/nature.jpg", ios_base::binary|ios_base::out);
        if (out.is_open())
        {
            char* buf = new char[255];
            while (in.good())
            {
                in.read(buf, 255);
                int count = in.gcount();
                out.write(buf, count);
            }
            out.close();
        }
        in.close();
    }
    return 0;
}

 

示例展示:

原來的文件:

 

運行程序后:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM