Ubuntu中c/c++语言简单程序编写以及使用gcc/g++方式编译简单程序(基础)
这里写目录标题
一、编写hello world入门
1、安装vim
在Ubuntu桌面按鼠标右键或者Ctrl+Alt+T打开终端
输入sudo apt-get install vim安装vim
sudo apt-get install vim
2、编写简单helloworld程序
(1) 创建目录helloworld(也可以不创建,就在默认目录下),输入mkdir helloworld
mkdir helloworld
(2) 打开helloworld文件夹
cd helloworld
(3)创建hello.cpp/hello.c文件
vim hello.cpp
(4)输入hello.cpp文件
#include<iostream>
using namespace std;
int main()
{
cout<<"hello world!";
return 0;
}
(5)编译hello.cpp,输入g++ hello.cpp(默认下生成a.out可执行文件,改变成其他文件名需要在后面加 -o filemame)
g++ hello.cpp
(6) 执行可执行文件a.out
./a.out
(7)输出结果
二、使用gcc编译c/c++简单主/子程序
(1)创建一个main1.cpp文件
vim main1.cpp
(2) 编写一个main1.cpp程序
#include<iostream>
#include"sub1.cpp"
using namespace std;
int main()
{
int a,b