English 中文(简体)
Sigbus on setd:map.find
原标题:Sigbus on std::map.find
  • 时间:2011-02-01 10:15:09
  •  标签:
  • c++
  • stl

我在头盔人员档案中的一门课内绘制了一个地图:

std::map<int, char> mCompletedIds;

我可以在这里与病媒打交道,因为我刚刚需要储存已经完成的ids。 但为了迅速找到,我正在使用地图。 因此,我总是把第2个奶粉论点说成是零。

现在, 在一组人中,我发现了这一点。

std:map<int, char>:iterator it = mCompletedIds.find(id);/id is defined above

On this statement, I am getting SIGBUS. Is it because map is empty at the moment? Can anyone pls. help me understand the reason.

Thanks, sg

最佳回答

如果你只想存储号码,你可以使用<代码>std:set<int>。

是否使用价值

std::set<int> mCompletedIds;
bool found = mCompletedIds.count(id) != 0; 

您的SIGBUS错误通常会由您的法典中发生的不一致或某些其他腐败造成,而一种工具,如valgrind。 如果你真的错误,可向你表示。

问题回答

int id = 0;

std::set<int> idList;
std::set<int>::iterator it = idList.find(id); //see also count function
if (it != idList.end()) { // find will return set::end if the element is not found
    // id is in your list
} else {
    // id isn t in your list
}




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签