How to read terminal argument

korkhg15·2022년 5월 24일
0

C++

목록 보기
2/4

We can use 'boost' libraries to read arguments,
but you know, in this page, we use the normal and easier way to read arguments

#include <iostream>
#include <string>
#include <queue>

int main(int argc, char** argv)
{
  int numbers = argc; //number of arguments
  std::queue<std::string> argv_tmp; //arguments queue
  int i=0;
  while (i<argc){
    argv_tmp.push(argv[i]);
    std::cout << argv_tmp.back() << std::endl;
    i++;
  }
  return 0;
}

I guess, you can say, as upper codes and picture,
the first argv argument(argv[0]) is always the file name (in this case sim)
then, the arguments you want to input is start from argv[1]

0개의 댓글