没有 std::to_u16string 或 std::to_u32string 吗?
我很高兴标准库获得了 to_string
函数,但现在我处于 WTF 模式。首先,为什么这不是模板化的,其次,如果它不是返回值的模板,那么为什么他们没有 to_u16string()
和 to_u32string()< /代码> 功能。
我知道有 boost 词法转换,但我很好奇是否有一种标准方法可以在不手动编写这些函数的情况下获得我想要的东西?
编辑:更糟糕的是 boost 1.46 也不喜欢 u16string :(
boost::lexical_cast<u16string>(22.44);
抛出实例后调用终止 'boost::exception_detail::clone_impl
<块引用>'what():词法转换错误:源类型值无法解释为目标
I was happy for the standard library to get a to_string
function, but now I'm in WTF mode. First of all why isn't this templated, second of all if it is not a template on return value then why in the world they don't have to_u16string()
and to_u32string()
functions.
I know that there is boost lexical cast, but I'm curious to know if there is a standard way to get what I want without manually writing these functions?
EDIT: to make matters worse boost 1.46 also dislikes u16string :(
boost::lexical_cast<u16string>(22.44);
terminate called after throwing an instance of
'boost::exception_detail::clone_impl' what(): bad lexical cast: source type value could not be interpreted as target
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在倒下之前放松并深呼吸。
这一切都很有道理。
to_string
和to_wstring
使用sprintf
/wsprintf
。该语言中没有任何内容跨越不可知的窄/宽编码和 UTF 编码之间的桥梁,因此根本不存在用于生成 UTF 编码字符串的标准库工具。新的 UTF 功能允许您存储 UTF 编码的字符串并在它们之间进行转码,但是如果没有额外库的帮助,则无法将系统特定的编码编码为 UTF 编码。您提议的“20 行代码”会是什么样子?请包括浮点数。
(以下是我关于该主题的标准问题链接:#1,#2,#3)
Relax and take a deep breath before you collapse.
It all makes perfect sense.
to_string
andto_wstring
usesprintf
/wsprintf
. There is nothing in the language that crosses the bridge between agnostic narrow/wide encoding and the UTF encodings, so there simply does not exist a standard library facility to produce UTF-encoded strings. The new UTF-facilities allow you to store UTF-encoded strings and transcode among them, but there is no way to encode a system-specific encoding to a UTF-encoding without the help of an extra library.How would those "20 lines of code" look like that you propose? Include floating point numbers, please.
(Here are my standard question links on the subject: #1, #2, #3)