开发者

passing filename as arguments in c++

I have to pass four different text files in an argument in开发者_JS百科 c++ program. How do i pass??


int main(int argc, char ** argv) {
  std::vector<std::string> args(argv, argv+argc);
  for (size_t i = 1; i < args.size(); ++i) {
    std::string const & aFileName = args[i];
    // Do something with aFileName
  }
}


I assume you mean on the command line. When main is defined as

int main(int argc, char *argv[])

argc is the count of arguments and argv contains them. The first arg in the array will be the name of the process and the others are the arguments passed to it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜