问题描述
我正在使用一个以字符串作为键的地图和一个存储
的结构。
struct StateType
{
int i;
浮动f;
char * s;
}
typedef std :: map< std :: string,StateType> ItemStateMap;
ItemStateMap m_itemMap;
StateType状态;
state.s =" HelloWorld" ;;
m_itemMap [" FirstPosition"] = state;
这是我正在做的一个真正淡化的版本,但这是
正是它的确如此。我在m_itemMap [" FirstPosition"] = state上遇到了分段错误
。谁能告诉我我是什么?b $ b做错了什么?我试图使用
m_itemMap.insert(FirstPosition,状态),但这不会编译。
提前谢谢
subaruwrx88011
I am using a map that takes an string as the key and a structure that
is being stored.
struct StateType
{
int i;
float f;
char* s;
}
typedef std::map<std::string, StateType> ItemStateMap;
ItemStateMap m_itemMap;
StateType state;
state.s = "HelloWorld";
m_itemMap["FirstPosition"] = state;
This is a really watered down version of what I am doing but this is
exactly what its doing in a nutshell. I am getting a segmentation fault
on m_itemMap["FirstPosition"] = state. Can anyone tell me what I am
doing wrong? I tried to use
m_itemMap.insert("FirstPosition", state) but that wouldn''t compile.
Thanks in advance
subaruwrx88011
推荐答案
我会告诉你什么你做错了。你不是在听,而不是学习b $ b。可编辑后代码。
我们无法告诉你淡化版本有什么问题。如果
淡化版本没有出现问题。
目前问题是最后两行;它们存在于文件
范围内,它们需要进入主要或其他功能。
Ben Pope
-
我不只是一个数字。对于很多人来说,我被称为字符串...
I''ll tell you what you are doing wrong. You''re not listening, and not
learning. POST COMPILABLE CODE.
We cannot tell you what is wrong with a "watered down version" if the
watered down version does not exhibit the problem.
At the moment the problem is the last two lines; they exist at file
scope, they need to go inside main, or another function.
Ben Pope
--
I''m not just a number. To many, I''m known as a string...
当然不会。你试图使用的''insert''需要一个参数
- 一对。 RTFM。
V
-
请在邮寄回复时从我的地址中删除资金
Of course it won''t. ''insert'' that you''re trying to use takes one argument
-- a pair. RTFM.
V
--
Please remove capital As from my address when replying by mail
(抱歉,我是不要在地图上。但我希望我的其他想法都有帮助。)
-Howard
(Sorry, I''m not up on maps. But I hope my other thoughts are helpful.)
-Howard
这篇关于Seg Fault帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!