我写了一个小程序,将一组字符串插入std :: set。
为此,我在.h文件中定义了一个set变量,然后在我的main函数中,我只是对.h文件中定义的集合做了惰性。
我正在获得核心转储,这里是相同的堆栈跟踪
#0 0x007a14a1 in std::string::compare () from /usr/lib/libstdc++.so.6
#1 0x080d459c in std::operator< <char, std::char_traits<char>, std::allocator<char> > (__lhs=@0xbfef09d0, __rhs=@0x87de230) at /usr/lib/gcc/i386-redhat- linux/3.4.6/../../../../include/c++/3.4.6/bits/basic_string.h:2158
#2 0x080d4580 in std::less<std::string>::operator() (this=0xb65d530, __x=@0xbfef09d0, __y=@0x87de230) at /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_function.h:227
#3 0x0810411a in std::_Rb_tree<std::string, std::string, std::_Identity<std::string>, std::less<std::string>, std::allocator<std::string> >::insert_unique (this=0xb65d530, __v=@0xbfef09d0) at /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_tree.h:919
#4 0x0810246c in std::set<std::string, std::less<std::string>, std::allocator<std::string> >::insert (this=0xb65d530, __x=@0xbfef09d0) at /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_set.h:314
示例代码:
X.h
std::set<string> test;
X.C
int main()
{
test.insert("hi");
return 0;
}
有人可以告诉我我正在做的错误吗?