boost::lexical_cast 从字符串到字符异常
我对使用 boost::lexical_cast 很陌生,对其内部结构了解甚少。我正在尝试执行以下转换:
string someString = boost::lexical_cast<char>(sourceString);
但是,boost 抱怨上面的代码是:
[Exception]: bad lexicalcast: source type value Could not beterpreted as target
The source 是一个字符串,但它始终只是 1字符长。
有人可以解释一下吗?
谢谢。
I am new to using boost::lexical_cast and have minimal understanding of its internals. I am trying to do the following cast:
string someString = boost::lexical_cast<char>(sourceString);
However, boost is complaining that the above code is:
[Exception]: bad lexical cast: source type value could not be interpreted as target
The source is a string, however it will always only be 1 character long.
Could someone please explain?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当我测试它时(修复从
char
到string
的无效转换后),只要sourceString
包含单个字符,词法转换就会成功。 这里是测试结果。如果您的真实代码不起作用,请发布更多代码;最好是一个可运行的程序来演示错误。
When I test it (after fixing the invalid conversion from
char
tostring
), the lexical cast succeeds as long assourceString
contains a single character. Here are the test results.If your real code doesn't work, then please post more of it; preferably a runnable program that demonstrates the error.