I am using Visual Studio 2013 for development, which uses Microsoft's C12 compiler tools v12.
The following code does a fine by typing "foo" on the console:
#include <regex> #include <iostream> #include <string> 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.
The same code replacing the string "s" for the function "get ()" throws an error "string iterators incompatible" at runtime:
#include <regex> #include <iostream> #include <string> std::string get() { return std::string("foo bar"); } int main() { std::smatch matches; std::regex_match(get(), matches, std::regex("^(foo).*")); std::cout << matches[1] << std::endl; } // Debug Assertion Failed! // Expression: string iterators incompatible
It makes no sense to me. Can anyone explain why this is happening?
c ++ regex visual-studio
slbelden
source share