c++ 编译问题

本文介绍了一个简单的 C++ 程序中使用 vector 的编译错误,并解释了使用 gcc 和 g++ 命令的区别。当使用 gcc 编译包含 C++ 标准库的程序时会出现错误,正确做法应使用 g++ 进行编译。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一个简单的vector 的c++ 程序, 编译错误

#include <vector>

int main()

{

std::vector<int> vet;

}

错误原因:使用的gcc 命令(应该使用g++命令)
gcc :

“GCC” is a common shorthand term for the GNU Compiler Collection. This is both the most general name for the compiler, and the name used when the emphasis is on compiling C programs (as the abbreviation formerly stood for “GNU C Compiler”).

使用gcc 编译c++程序,虽然gcc也能识别出c++,但gcc并不会加载c++ library


g++:

而使用g++ 编译c++程序,会调用gcc而且会自动加载c++ library


please refer:

* http://gcc.gnu.org/onlinedocs/gcc-3.3.6/gcc/G_002b_002b-and-GCC.html
* man g++
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值