__wargv在vs工程中代表着命令行的参数
__argc在vs工程中代表着命令行的参数个数
所以, 当要获取命令行中的参数时,可以使用如下代码:
vector<string> args;
for (int i = 0; i < __argc; ++i)
{
wstring ws(__wargv[i]);
string s;
s.assign(ws.begin(), ws.end());
args.push_back(s);
}
auto it = args.begin();
while (it != args.end())
{
if (it->find_first_of('-') == 0)
{
//find a parameters key
std::string key = it->substr(1);
++it;
if (it == args.end())
{
break;
}
std::string val = *it;
_argsMap.insert(std::make_pair(key, val));
}
++it;
}