0

我写了一个小程序将一组字符串插入到 std::set 中。

为此,我在 .h 文件中定义了一个集合变量,然后在我的主函数中,我只是对 .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;
    }

有人可以让我知道我正在做的错误吗?

4

0 回答 0