关于C++命令行
代码如下:#include<iostream>
#include<fstream>
#include<cstdlib>
#include<string>
int main(int argc, char *argv[])
{
using namespace std;
if (argc == 1)
{
cerr << "请输入至少两个字符串!\n";
exit(EXIT_FAILURE);
}
string tem;
ofstream fout;
fout.open(argv[1],ios_base::out|ios_base::app);
if (!fout.is_open())
{
cout << "无法打开 " << argv[1] << " 文件!\n";
exit(EXIT_FAILURE);
}
getline(cin, tem);
while (!cin.eof())
{
fout << tem;
getline(cin, tem);
}
fout.close();
return 0;
}
运行时只能看到:请输入至少两个字符串!
求大神解答疑惑!
[此贴子已经被作者于2017-12-29 20:12编辑过]