C++ 文件读写(拷贝)/Makefile
来源:互联网 发布:交换机端口安全配置 编辑:程序博客网 时间:2024/06/05 16:43
1. C++ 代码 (copy.cpp)
#include<iostream>#include<string>#include<fstream>using namespace std;int main(int argc, char *argv[]){ if(argc != 3){ cerr<<"error: no source file or target file."<<endl; exit(-1); } ifstream sourceFile(argv[1]); ofstream targetFile(argv[2]); if(!sourceFile || !targetFile){ cerr<<"error: sourceFile or targetFile open failed."<<endl; exit(-1); } string line;/* while(sourceFile>>line){ //read a word each time targetFile<<line; }*/ while(getline(sourceFile, line)){ targetFile<<line; if(!sourceFile.eof()) targetFile<<endl; } sourceFile.close(); targetFile.close(); return 0;}2. Makefile
[root@node14 io]# cat Makefilesrc=copy.cppdist=copysourceFile=source.tar.gztargetFile=target.tar.gzall:runcompile:${src} g++ -g -w ${src} -o ${dist}run:compile ./${dist} ${sourceFile} ${targetFile}clean: -rm ${targetFile} -rm ${dist}clear: @if [ -f ${targetFile} ] && [ -f ${dist} ]; then\ rm ${targetFile};\ rm ${dist};\ fi
3. 执行
[root@node14 io]# make
[root@node14 io]# ll
[root@node14 io]# make clean 或者 make clear
- C++ 文件读写(拷贝)/Makefile
- C例程:文件读写 拷贝 标准输入输出等
- C/C++:拷贝文件
- 利用C语言文件读写做的一个文件拷贝功能
- 文件读写简单实例---拷贝文件
- Qt4 简单读写文件及文件拷贝
- 【C/C++】文件读写
- C语言文件拷贝
- 拷贝文件(c)
- c文件拷贝
- c语言读写文件
- 文件读写(c)
- C#-读写INI文件
- [C++]文件读写操作
- C#读写INI文件
- C 读写文件
- C读写ini文件
- c#FileStream文件读写
- Arduino克隆
- AndroidManifest.xml解析(一)
- 学前教育专业课程建设研讨会暨国家精品资源共享课建设调研会
- STC单片机无法下载故障总结
- 带头结点的链表
- C++ 文件读写(拷贝)/Makefile
- AndroidManifest.xml解析(二)
- asp.net 文件下载时,出现非法路径解决方案
- linux临时文件
- enqueue:HW问题分析与解决
- AndroidManifest.xml解析(三)
- 没有对“C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files”的写访问权限
- 左值与右值(最基本的你懂吗?)
- 带 参数 ajax请求(利用getjson方法按客户id来请求客户信息)