Command Line Arguments

Is it possible to access command line arguments with the C++ string class instead of a char array?
Nothing stops you from:

1
2
3
4
5
6
int main(int argc, char *argv)
{
    std::string myArg = arg[0];
    //Now the first argument has been copied as a std::string class in variable myArg.
    ....
}

You can do:
1
2
3
4
5
6
7
8
9
#include <string>
#include <vector>

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

    // now vector args has your arguments as std::strings
}
Topic archived. No new replies allowed.