c++文件操作

#include<iostream>
#include <fstream>
using namespace std;
/*文本文件
void main() {
    char* fname = "d://dest.txt";
    ofstream fout(fname);
    //如果节点流发生致命错误返回true
    if (fout.bad())
    {
        return;
    }

    fout << "i love youasdasdasdasdasdasd" << endl;
    fout << "112asdsdasdasdasdasdas" << endl;
    fout << "2" << endl;

    fout.close();

    if (fout.bad()) {
        return;
    }

    ifstream fin(fname);
    char *line ="";
    const int LINE_LENGTH = 51;
    char t[LINE_LENGTH];
    char str[LINE_LENGTH];

    while (fin.getline(str,LINE_LENGTH))
    {
        cout << "Read from file: " << str << endl;
    }
    system("pause");
};*/

//拷贝二进制文件
void main() {

    char* fname = "d://a.jpg";
    char* fname2 = "d://b.jpg";

    //读入文件 以二进制方式
    ifstream fin(fname,ios::binary);
    //读取 以二进制方式
    ofstream fout(fname2,ios::binary);

    if (fin.bad()||fout.bad())
    {

        return;

    }


    while (!fin.eof())
    {
        char buff[1024] = { 0 };
        fin.read(buff,1024);
        fout.write(buff,1024);
    }

    fin.close();
    fout.close();

    getchar();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值