我正在使用Visual Studio 2013进行开发,它使用了Microsoft的c编译工具v12.
以下代码执行正常,将“foo”打印到控制台:
#include
#include
#include
std::string get() {
return std::string("foo bar");
}
int main() {
std::smatch matches;
std::string s = get();
std::regex_match(s,matches,std::regex("^(foo).*"));
std::cout << matches[1] << std::endl;
}
// Works as expected.
使用字符串“s”替换“get()”函数的相同代码在运行时抛出“string iterators incompatible”错误:
#include
#include
#include
std::string get() {
return std::string("foo bar");
}
int main() {
std::smatch matches;
std::regex_match(get(),std::regex("^(foo).*"));
std::cout << matches[1] << std::endl;
}
// Debug Assertion Failed!
// Expression: string iterators incompatible
这对我没有意义.谁能解释为什么会这样?