这个
std::regex line("[\s]+\+?[0-9]+.[0-9]+[\s]+\+?[0-9]+.[0-9]+[\s]+\+?[0-9]+.[0-9]+[\s]");
线路导致此问题
Exception thrown at 0x00007FFE39E69E08 in DosyaOkuHizli.exe: Microsoft C++ exception: std::regex_error at memory location 0x000000F751EFEAB0.
Exception thrown at 0x00007FFE39E69E08 in DosyaOkuHizli.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
Exception thrown at 0x00007FFE39E69E08 in DosyaOkuHizli.exe: Microsoft C++ exception: std::regex_error at memory location 0x000000F751EFEAB0.
Unhandled exception at 0x00007FFE39E69E08 in DosyaOkuHizli.exe: Microsoft C++ exception: std::regex_error at memory location 0x000000F751EFEAB0.
但是这个
std::regex line("abc");
没有。
长表达式在这里起作用:https://www.myregextester.com/index.php
我只是想获取其他数据之间的 3 个后续浮点值。
Visual Studio 2015 社区版调试 64 位。 Windows 10。
最佳答案
您需要使用 \\
转义反斜杠(两个为一),或者使用像这样的原始字符串文字:
regex line{R"([\s]+\+?[0-9]+.[0-9]+[\s]+\+?[0-9]+.[0-9]+[\s]+\+?[0-9]+.[0-9]+[\s])"};
原始字符串文字(至少)用 R"(
和 )"
包围字符串。
了解有关原始字符串文字的更多信息 HERE - 语法 (6)。
关于c++ - 长正则表达式会导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44705302/