C++ STL库使用注意点

STL使用

在linux环境下写了一个C++程序,里面用到了STL的库函数,编译时报了很多错误。

/usr/include/c++/5/bits/stl_list.h:507:11: note:   ‘std::__cxx11::list’
main.cpp:35:10: error: ‘string’ was not declared in this scope
     list<string> strList;
          ^
main.cpp:35:10: note: suggested alternatives:
In file included from /usr/include/c++/5/iosfwd:39:0,
                 from /usr/include/c++/5/ios:38,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from main.cpp:1:
/usr/include/c++/5/bits/stringfwd.h:74:33: note:   ‘std::__cxx11::stringtypedef basic_string<char>    string;   
                                 ^
/usr/include/c++/5/bits/stringfwd.h:74:33: note:   ‘std::__cxx11::string’
main.cpp:35:18: error: ‘strList’ was not declared in this scope
     list<string> strList;
                  ^
main.cpp:43:22: error: ‘::iterator’ has not been declared
     for (list<string>::iterator iterStrList = strList.begin(); iterStrList != strList.end(); iterStrList++)
                      ^
main.cpp:43:22: note: suggested alternatives:
In file included from /usr/include/c++/5/bits/stl_algobase.h:65:0,
                 from /usr/include/c++/5/bits/char_traits.h:39,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from main.cpp:1:
/usr/include/c++/5/bits/stl_iterator_base_types.h:118:12: note:   ‘std::iterator’
     struct iterator
            ^
/usr/include/c++/5/bits/stl_iterator_base_types.h:118:12: note:   ‘std::iterator’

由于所有标准模板库均在std域名空间内,所以上面一堆错误都是因为没有指定标准域名空间导致,所以千万不要忘加“using namespace std;”

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JXES智能生态系统

如文章对你有用,请作者喝个咖啡

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值