简而言之,以下代码本质上有什么问题?
#include <regex>
int main() {
std::regex_match(u" ", std::basic_regex<char16_t>{u" "});
}
它的错误
$ g++ -std=c++17 main.cpp -o main
$ ./main
terminate called after throwing an instance of 'std::bad_cast'
what(): std::bad_cast
Aborted (core dumped)
更多信息:
$ g++ --version
g++ (GCC) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
最佳答案
C++ 标准库不支持 char16_t 或 char32_t Unicode 的正则表达式。有一个提案可以解决这个问题,但它不在 C++20 中:http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0169r0.html
关于regex - 我可以在 char16_t 字符串上使用 STL 正则表达式库吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64007157/