I have a program that reads hard-coded file-path and I want to make it read file-path from command line instead. For that purpose I changed the code like this:
#
You can create an std::string
#include
#include
int main(int argc, char *argv[])
{
// check if there is more than one argument and use the second one
// (the first argument is the executable)
if (argc > 1)
{
std::string arg1(argv[1]);
// do stuff with arg1
}
// Or, copy all arguments into a container of strings
std::vector allArgs(argv, argv + argc);
}