ubuntu下CC++编程起步

it2022-05-09  41

1. 安装VMware虚拟机软件

 

2. 在VMware中安装linux系统,这里安装的是Ubuntu。(用 VMware 安装 Ubuntu 12.04详细过程图解

 

3. ubuntu有自带文本编辑器,我们可以创建一个文档。然后输入代码,讲名字改为*.c。还可以使用另外一个文本编辑器vi。如果你的ubuntu没有,那我们可以在终端输入:

       sudo apt-get install vim

 完成后我们就有一个非常强大的编辑器vi

 

4. 编译ubuntu上第一个c语言程序

在主文件夹中,建立一个hello.c的文件,双击文件输入代码:#include <stdio.h>int main(void){    printf("Hello,ubuntu!\n");    return 0;}然后保存。

或者可以在终端输入:  vim hello.c然后同样输入代码保存。

然后在终端输入:    gcc hello.c -o hello如果没有发现错误,那就再输入./hello那么在终端里,就可以看到程序输出:Hello,ubuntu!

 

5. 如果要编译c++,那么先要配置环境。安装build-essential,可以在新立得搜索然后安装或者在终端里输入:    sudo apt-get install build-essential

 

6. 建立一个hello.cpp的文件,编写代码:

#include <iostream>using namespace std;int main(){    cout << "Hello Ubuntu C++!" << endl;    return 0;}

然后在终端输入:    g++ hello.cpp -o hello    ./hello

即可看到程序输出:Hello Ubuntu C++!

 

 

转载于:https://www.cnblogs.com/lxt287994374/p/3844192.html

相关资源:数据结构—成绩单生成器

最新回复(0)