A
amphetaman
Hello. I am writing code to put the traditional C-style command-line
arguments into a std::vector of std::strings. I was wondering: which
is the best way to do it? Are they identical?
#include <string>
#include <vector>
int mymain(const std::vector<std::string> &);
int main(int argc, char *argv[])
{
std::vector<std::string> theArgv;
for (int i = 0; i < argc; i++)
{
// a) or b) ?
}
return mymain(theArgv);
}
a) theArgv.push_back(argv);
b) theArgv.push_back(std::string(argv));
Any help is appreciated.
arguments into a std::vector of std::strings. I was wondering: which
is the best way to do it? Are they identical?
#include <string>
#include <vector>
int mymain(const std::vector<std::string> &);
int main(int argc, char *argv[])
{
std::vector<std::string> theArgv;
for (int i = 0; i < argc; i++)
{
// a) or b) ?
}
return mymain(theArgv);
}
a) theArgv.push_back(argv);
b) theArgv.push_back(std::string(argv));
Any help is appreciated.