linux下C++基础操作

2018-05-11

环境配置

OS: ubuntu16.04

安装编译器

gcc

验证是否已经安装:g++ --version

编译第一个c++代码并运行。

首先编写‘src.cpp’文件:

//头文件
#include <iostream>
#include <stdlib.h>
// 命名空间
using namespace std;

int main(void){
  cout << "请输入一个整数:" << endl;
  int x = 0;
  cin >> x;
  cout << "八进制:" << oct << x << endl;
  cout << "十进制:" << dec << x << endl;
  cout << "十六进制:" << hex << x << endl;

  cout << "Hello World" << endl;
}

然后编译源代码:

g++ src.cpp -o first_demo

最后运行编译好的程序first_demo:

./first_demo