用gcc怎样编译STL的c++程序?

vcvcc 2004-11-22 11:39:24
如下一个简单的程序

//////////////////////////////////////////////////////////////////////////////
//test.cpp

#include <iostream>
#include <vector>
using namestd
void main()
{
int i;
vector<int> vt;
vector<int>::iterator it;
for(i=0; i<5; i++)
vt.push_back(i);
for(it=vt.begin(); it !=vt.end(); it++)
count << *it <<endl;
}

用gcc编译不连接没有错误
gcc -c test.cpp //ok!
然后连接
gcc -o test.exe test.o //这里出错!

ps,用g++编译没有问题。

问题:如果要用gcc指令编译应怎样做?
...全文
830 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
痞子酷 2004-11-24
  • 打赏
  • 举报
回复
#include <vector>
using namespace std;

void main()
{
int i;
vector<int> vt;
vector<int>::iterator it;
for(i=0; i<5; i++)
vt.push_back(i);
for(it=vt.begin(); it !=vt.end(); it++)
count << *it <<endl;
}
tukey 2004-11-24
  • 打赏
  • 举报
回复
man g++
wxywh 2004-11-24
  • 打赏
  • 举报
回复
能用g++为什么要用gcc呢?
pacman2000 2004-11-23
  • 打赏
  • 举报
回复
gcc编译C++的东西要指定连接C++的库。g++是默认就连接。能用g++为什么要用gcc呢?
garry_zhang 2004-11-23
  • 打赏
  • 举报
回复
using namestd??
是否using namespace std
liulcy 2004-11-23
  • 打赏
  • 举报
回复
g++命令就可以了,或者再加上-I /usr/linux/include/g++-3/用于连接C++库,等等
lijiangshui 2004-11-23
  • 打赏
  • 举报
回复
#include <iostream>
#include <vector>
using namestd
~~~~~~~这也可能,老兄用的什么编译器啊,呵呵:)

23,125

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧