LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 865|回复: 5

请问如何在linux下编译带stl的程序

[复制链接]
发表于 2006-2-4 18:07:52 | 显示全部楼层 |阅读模式
以下是我的程序:

  1. #include <string>
  2. #include <list>
  3. int main () {

  4.         list<string> s;
  5. }
复制代码



  1. g++ test.cpp
复制代码
编译

结果:
  1. test.cpp: In function `int main()':
  2. test.cpp:5: error: `list' undeclared (first use this function)
  3. test.cpp:5: error: (Each undeclared identifier is reported only once for each function it appears in.)
  4. test.cpp:5: error: `string' undeclared (first use this function)
  5. test.cpp:5: error: `s' undeclared (first use this function)
复制代码
发表于 2006-2-4 19:03:52 | 显示全部楼层
加上std::
回复 支持 反对

使用道具 举报

发表于 2006-2-4 19:49:14 | 显示全部楼层
list等STL容器在std名字空间中。
GCC是较完整的支持标准C++的编译器之一。
相比之下VC6对标准的支持弱一些(VC7很好)
回复 支持 反对

使用道具 举报

发表于 2006-2-5 17:04:31 | 显示全部楼层
Post by MatthewGong
相比之下VC6对标准的支持弱一些(VC7很好)

更确切的说是VC7.1还好。VC7的编译器和STL也是半斤八两。
回复 支持 反对

使用道具 举报

发表于 2006-2-5 18:49:45 | 显示全部楼层

  1. using namespace std;
复制代码
回复 支持 反对

使用道具 举报

发表于 2006-2-7 09:25:36 | 显示全部楼层
#include <string>
#include <list>
using namespace std
int main () {

        list<string> s;
}
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表