我使用 Visual C++ 2012 编写了以下代码来解析命令行参数。 这些命令行参数具有传统的 GNU 风格(--option)。
void parseCmdLines(int argc, wchar_t* argv[]) {
for (auto i = 1; i < argc; ++i) {
std::wstring arg(argv[i]);
// I hope it can match the L"--config=../etc/my.conf"
std::wregex regex(L"--config=(+*)");
std::wsmatch match;
std::regex_match(arg, match, regex);
// TODO: ...
}
不幸的是,当我运行这个程序时,我遇到了异常。异常描述如下:
Microsoft C++ exception: std::regex_error at memory location 0x23F090.
如何解决这个问题?
最佳答案
您的问题可能出在 +*
上。
+
表示出现在其前面的一个或多个内容,而 *
表示出现在其前面的零个或多个内容(因为有一个 (
在 +
之前,它不应该工作,因为这仅仅意味着一个组的开始,而对于 *
之前的 +
,你不能真正说“零个或多个一个或多个”)。
您可能指的是 .*
(即零个或多个任何内容)或 .+
(即一个或多个任何内容)?
关于c++ - Microsoft C++ 异常:内存位置处的 std::regex_error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18015254/