C ++:从命令行读取文件名,并在我的文件中使用它 [英] C++ : Read a file name from the command line and utilize it in my file

查看:676
本文介绍了C ++:从命令行读取文件名,并在我的文件中使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从命令行读取文件名并在我的c ++代码文件中使用它?

How can I read a filename from the command line and utilize it in my c++ code file?

ex:./cppfile inputFilename outputFilename

ex: ./cppfile inputFilename outputFilename

任何帮助都非常感谢!

推荐答案

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;
    }
    ...
}

这篇关于C ++:从命令行读取文件名,并在我的文件中使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆