Skip to content

Instantly share code, notes, and snippets.

@LB--
Created November 16, 2014 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LB--/f7b2dfa51c71824a13d6 to your computer and use it in GitHub Desktop.
Save LB--/f7b2dfa51c71824a13d6 to your computer and use it in GitHub Desktop.
C++ program arguments - my personal favorite way to get them into a vector of strings. No undefined behavior.
#include <iostream>
#include <string>
#include <vector>
int main(int, char const *const *plain_args)
{
std::basic_string<char const *> const temp {plain_args};
std::vector<std::string> const args {std::begin(temp), std::end(temp)};
for(auto const &arg : args)
{
std::cout << '"' << arg << '"' << std::endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment