【发布时间】:2013-05-25 15:41:54
【问题描述】:
我有一个包含端口的字符串,当我尝试创建一个 tcp 端点时,我需要它的 unsigned short 值
std::string to_port;
....
boost::lexical_cast<unsigned short>(to_port));
抛出异常bad lexical cast: source type value could not be interpreted as target
【问题讨论】:
-
它对我有用。
to_port包含什么? -
例如“8004”或任何端口号
-
this example 不适合你吗?
-
请向我们发送演示问题的完整(但最小)程序
-
可能想在
lexical_cast<>的行上插入一个断点并验证to_port的内容是否正确。
标签: c++ boost lexical-cast