[C/C++] C/C++语言文件读写函数
来源:互联网 发布:个人域名如何备案 编辑:程序博客网 时间:2024/06/05 09:41
学习自“知道蚂蚁” 点击打开链接
#include <stdlib.h>#include <stdio.h>using namespace std;int main(){FILE *fpSrc, *fpDes;fpSrc = fopen("execute.stdin", "r"); // 打开[没有则创建]文件读取数据fpDes = fopen("destfile.stdin", "w"); // 打开文件写入数据if (fpSrc == NULL || fpDes == NULL){printf("文件打开错误!");exit(-1); // 非正常退出}char cVal;while ((cVal = fgetc(fpSrc)) != EOF) // 判断是否读完文件{fputc(cVal, fpDes); // 将源文件中内容复制大目标文件}fclose(fpSrc);fclose(fpDes); // fcloseall(); 关闭多个文件system("pause");return 0;}
/*C++代码如下:*/#include <iostream>#include <fstream>using namespace std;int main(){ifstream ifs("execute.stdin");ofstream ofs("destfile.stdin");int iVal;while ( ifs >> iVal ) // 判断是否读完文件{ofs << iVal; // 将源文件中内容复制大目标文件}ifs.close();ofs.close();system("pause");return 0;}
阅读全文
0 0
- [C/C++] C/C++语言文件读写函数
- c语言读写函数
- c语言读写文件
- C语言读写文件
- C语言读写文件
- C语言文件读写
- C语言读写文件
- C语言文件读写
- C语言文件读写
- C语言读写文件
- C语言文件读写
- C语言读写文件
- C语言读写文件
- C语言读写文件
- C语言文件读写
- C语言读写文件
- C语言读写文件
- C语言 读写文件
- 最长公共子串(动态规划的思想)
- 51nod 1832 先序遍历与后序遍历(树的遍历方法+高精度模板)
- QT和MFC
- s2s4h5整合
- Java实现矩阵顺时针旋转90度
- [C/C++] C/C++语言文件读写函数
- [springcloud]eureka注册服务小案例
- 2017.9.9-2017.9.10---训练赛
- 基于centos的nginx安装配置
- 9月10日周日训练笔记
- 继承与多态
- 最长非递减子序列模板
- 移动端车牌识别嵌入至手机app中
- 赛码网编程练习题_1