枚举的分段错误
我有以下功能
template<class T> T stringTo(const std::string& s)
{
std::istringstream iss(s);
T x;
iss>>x;
return x;
};
,当我按如下方式应用它时:
session ft = stringTo<session>("F");
会话在哪里:
enum session {F, S, T};
我收到分段错误。
你能帮我找出我的错误出在哪里吗...
I have the following function
template<class T> T stringTo(const std::string& s)
{
std::istringstream iss(s);
T x;
iss>>x;
return x;
};
and when I apply it as follows:
session ft = stringTo<session>("F");
where session is:
enum session {F, S, T};
I get a Segmentation fault.
can you help me figure out where my error lies...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题可能是您使用的是
'F'
而不是"F"
吗?看起来您的
stringTo
函数需要一个string
而您正在发送一个char
。顺便说一句,我认为你的方法无效。您可能需要设置一个从字符串到枚举的映射,反之亦然。
也许,这可能会给你一个选择。
Could the problem be that you are using
'F'
instead of"F"
?It seems like your
stringTo
function wants astring
and you are sending in achar
.Btw, I don't think your approach is valid. You probably need to setup a map that takes you from string to enum or vice versa.
Maybe, this might give you an option.