C++新手菜鸟学习记录
- 一般情况下gcc是C的编译器,g++是C++的编译器
- 后缀为.c的,gcc会把其当作是C程序,g++会把其当作是C++程序。
- 后缀是.cpp的,二者都会把其当作是C++程序
- 编译阶段,g++会调用gcc,但是gcc不会自动调用g++。所以大多数情况下,都会使用g++
- 在C++代码中,如果想让某些函数使用C编译,则可以使用extern "C"{函数},然后利用g++编译
举俩例子
- 写test.cpp
#include<iostream>
int main(){
std::cout<<"helloworld"<<std::endl;
}
-
利用g++编译
g++ -o t.out test.cpp
-
运行编译结果
./t.out
-
写test.c
#include<stdio.h>
int main(){
printf("helloworld");
}
- 利用g++编译
gcc -o t.out test.c
- 运行编译结果
./t.out