栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

c++ 文件读写用到的函数

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c++ 文件读写用到的函数

//读写二进制文件 例子
    FILE* fpr = fopen("1.mp4", "rb");
    FILE* fpw = fopen("2.mp4", "wb");
    if (fpr == NULL)return -1;
    if (fpw == NULL)return -1;
    char* chh = new char[100];
    string str;
    while (!feof(fpr))//读到文件末尾
    {
        memset(chh, 0, 100);
        int num = fread(chh, 1, 100, fpr);
        int ret = fwrite(chh, 1, num, fpw);///通过写文件流写入文件
    }
    cout << str;
    delete[]chh;
    fclose(fpr);
    fclose(fpw);
   

//读写文本文件   例子

ifstream ifs;
    ifs.open("a.txt", ios::in);
    ofstream ofs;
    ofs.open("d.txt", ios::out);
    if (ifs.is_open())
    {
        char buf[1024] = { 0 };
        while (ifs >> buf) { //只要能读到内容就打印信息
            cout << buf;
            int len = strlen(buf);
            ofs << buf;  ///通过写文件流写入文件
        }
    }

ifs.close();

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/347436.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号