如何从命令行读取文件名并在我的c ++代码文件中使用它?
ex:./ cppfile inputFilename outputFilename
非常感谢任何帮助!
答案 0 :(得分:8)
int main(int argc, char** argv) {
string inFile = "";
string outFile = "";
if( argc == 3 ) {
inFile = argv[1];
outFile = argv[2];
}
else {
cout << "Usage: ./cppfile InputFile OutputFile\n";
return 1;
}
...
}