大家好,这里是国中之林!
❥前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到网站。有兴趣的可以点点进去看看←
问题:
解答:
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc,char*argv[])
{
if (argc < 3)
{
cout << "Usage: " << argv[0] << " srcfile desfile" << endl;
exit(EXIT_FAILURE);
}
char ch;
ifstream fin(argv[1], ios_base::in);
ofstream fout(argv[2], ios_base::out);
if (!fin.is_open())
{
cout << "Can't open the file:" << argv[1] << "!" << endl;
exit(EXIT_FAILURE);
}
if (!fout.is_open())
{
cout << "Can't open the file:" << argv[2] << "!" << endl;
exit(EXIT_FAILURE);
}
while (fin.get(ch))
{
fout << ch;
}
fin.close();
fout.close();
return 0;
}
运行结果:
注意:
- 要先在vs中编译一下,再进行g++ main.cpp -o file.exe
- 这里的argc的参数个数就是三哦.
2024年9月22日15:21:20