zoukankan      html  css  js  c++  java
  • Ubuntu下第一个C程序的成功运行

    对于每个新手来说,进入Ubuntu最想做的事莫过于在终端(Terminal)里运行自己的第一个C/C++程序"hello.c/hello.cpp"了。

    很多语言书籍都是默认搭载好运行环境的,而Ubuntu默认是不包含编辑器vim。假设你和我一样,展现在自己眼前的是一台刚安装好的Ubuntu电脑,下面我们将来实现自己的第一个程序。

    1.准备工作

      1.1 打开控制台:使用快捷键 Ctrl + Alt + T

      1.2 安装vim:输入  sudo apt-get install vim ;

      *1.3 安装gcc(如果没有):输入  sudo apt-get install gcc

    2.编写hello.c源代码

      2.1 新建文件名为hello.c的源文件:输入 vim hello.c ;

      2.2 键入i 进入insert模式(即编辑模式),写入如下经典代码:

    1 //the first program hello.c
    2 #include<stdio.h>
    3 int main(void)
    4 {
    5     printf("Hello, world!
    ");
    6     return 0;
    7 }

      2.3 输入完成后,Esc 回到normal模式(命令模式),键入 :wq  保存退出vim。

    3.编译hello.c

      在终端执行   gcc hello.c -o hello  编译。

    4.运行程序hello

       ./hello 就看到结果:

    Hello,world!

  • 相关阅读:
    C++中public、protected、private的差别
    TSP问题
    Android百日程序:绘画程序-画手指路径
    DFS csu1719 Boggle
    Oracle数据库imp
    <html>
    SWIFT学习笔记05
    Xcode7 真机免证书调试Cocos2D游戏
    mycat 不得不说的缘分
    HashMap和Hashtable的差别
  • 原文地址:https://www.cnblogs.com/freyr/p/3648728.html
Copyright © 2011-2022 走看看