Skip to content

Latest commit

 

History

History
26 lines (21 loc) · 607 Bytes

File metadata and controls

26 lines (21 loc) · 607 Bytes

This pages shows how to convert argv to std::vector<std::string>.

#include <cassert>
#include <string>
#include <vector>

int main(int argc, char* argv[])
{
  const std::vector<std::string> args(argv, argv + argc);
  assert(argc == static_cast<int>(args.size());
  assert(argv[0] == args[0]);
}

To skip argv[0], use:

int main(int argc, char* argv[])
{
  const std::vector<std::string> args(argv + 1, argv + argc);
  // ...
}