basic_regex使用char32_t抛出bad_cast [英] basic_regex throws bad_cast with char32_t
本文介绍了basic_regex使用char32_t抛出bad_cast的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码为什么会生成 std :: bad_cast
异常?
Why does the following code generate std::bad_cast
exception?
#include <iostream>
#include <regex>
#include <string>
int main()
{
std::basic_string<char32_t> reg = U"^\\w";
try
{
std::basic_regex<char32_t> tagRegex(reg);
}
catch(std::exception &e)
{
std::cout << e.what() << std::endl;
}
return 0;
}
为方便起见,此示例在Ideone上: https://ideone.com/Saea88
This sample on Ideone for convenience: https://ideone.com/Saea88
使用 char
或 wchar
而不是 char32_t
运行但不会抛出错误(证明:
Using char
or wchar
instead of char32_t
runs without throwing though (proof: https://ideone.com/OBlXed).
推荐答案
查看全文