我调试过了 只有一处错误
使用方法 这个文件编译后的exe 假设叫 test.exe
那么 如果要读 1.txt 和 2.txt 那么 先要进入CMD(在运行里输入CMD回车)
不是你常用的控制台 虽然也是黑窗口
转到 test.exe所在目录 输入 test.exe 1.txt 2.txt 回车 就可以运行了 如果有路径 那么输入路径
有什么问题继续问 不行了远程协助
D:\Backup\我的文档\MyProjects\XLCS\20111217\Debug>20111217 1.txt 2.txt
1.txt内容
2.txt内容
请按任意键继续. . .
#include
#include
#include
using namespace std;
int main(int argc , char *argv[])
{
ifstream file1,file2;
file1.open(argv[1]);
string s;
while(!file1.eof())
file1>>s;
cout< file1.close();
file2.open(argv[2]);
while(!file2.eof()) //这里的 file2 手误成file1了
file2>>s;
file2.close();
cout< system("pause");
return 0;
}
int main(int argc , char *argv[]这个函数是要调用才能运行的, argc是指函数的输入参数的个数, argv指向字符串指针的指针,这是实际的输入参数的指针, 你可以自己百度一下windows下使用DOS环境调用函数,很简单的。
#include
#include
#include
using namespace std;
int main(int argc , char *argv[])
{
ifstream file1,file2;
file1.open(argv[0],ios::out);//这里改改
string s;
while(!file1.eof())
file1>>s;
cout< file1.close();
file2.open(argv[1],ios::out);//这里改改
while(!file1.eof())
file2>>s;
file2.close();
cout< system("pause");
return 0;
}
mian()函数是不能被其他函数调用的,但是 计算机的 操作系统 可以调用主函数。
具体方法:把源程序编译并链接后的可执行文件和要合并的CPP文件复制到D盘->将可执行文件重命名为mycomm.exe->打开命令提示符窗口->输入d:回车->然后输入 mycomm file1.cpp file2.cpp 回车->完毕 如果你的程序逻辑没错误 应该是能达到预期功能