• ubuntu14.04 配置g++工具,并运行一个简单的c++文件


    首先,对Ubuntu 14.04 LTS进行源更新,摘自下述链接:

    http://chenrongya.blog.163.com/blog/static/8747419620143185103297/

    对其源列表进行备份

    1 sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup
    注:  lsb_release -a 查看ubuntu版本号

    用编辑器gedit进行打开 sources.list

    1 sudo gedit /etc/apt/sources.list

    打开后,将下列服务器地址复制粘帖在最后,保存并关闭:

    deb http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
    
    deb http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
    
    deb http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
    
    deb http://archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
    
    deb http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
    
    deb-src http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
    
    deb-src http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
    
    deb-src http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
    
    deb-src http://archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
    
    deb-src http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse

    设置好上述后,对ubuntu 源进行更新:

    sudo apt-get update

    运行下述,即可实现g++工具的安装

    sudo apt-get install g++

    g++安装完成。

    创建一个简单的cpp文件

    1、打开终端:

    Ctrl + Alt + T

    2、创建一个main.cpp文件

    先创建一个文件夹(例如:CPP)
    mkdir CPP
    在文件CPP下,创建一个main.cpp文件
    cd CPP
    touch main.cpp
    创建完成后,打开main.cpp
    gedit main.cpp

    3、在main.cpp文件中输入:

    1 #include<iostream>
    2 using namespace std;
    3 int main()
    4 {
    5    cout<<"hello This is My first CPlusPlus!"<<endl;
    6    return 0;
    7 }

    4、运行main.cpp 文件

    1  g++ main.cpp  -o test
    2 ./test

    运行,输出。

  • 相关阅读:
    【leetcode】19. Remove Nth Node From End of List
    【leetcode】18. 4Sum
    【leetcode】371. Sum of Two Integers
    【leetcode】17. Letter Combinations of a Phone Number
    【leetcode】16. 3Sum Closest
    【leetcode】13. Roman to Integer
    【leetcode】15. 3Sum
    【leetcode】14. Longest Common Prefix
    【leetcode】368. Largest Divisible Subset
    Linux学习总结(十四) 文件的打包和压缩
  • 原文地址:https://www.cnblogs.com/LQLin168/p/6844593.html
Copyright © 2020-2023  润新知