在 Ubuntu 下学习 C++ 入门,可以按下面这条路线来,比较系统也实用。
Ubuntu 默认一般带 gcc,但 C++ 需要 g++:
sudo apt update
sudo apt install g++ build-essential
验证:
g++ --version
新手推荐:
VS Code(推荐)
sudo apt install code
安装 C/C++ 插件
或轻量一点:
geditvim(有学习成本)创建文件:
touch hello.cpp
内容:
#include <iostream>
using namespace std;
int main() {
cout << "Hello Ubuntu C++" << endl;
return 0;
}
编译运行:
g++ hello.cpp -o hello
./hello
cin / cout)if / switchfor / whilestring 基本用法&structclassg++ main.cpp -o main
了解:
g++ main.cpp func.cpp -o app
简单示例:
app: main.cpp func.cpp
g++ main.cpp func.cpp -o app
使用:
make
gdb 调试(后期)如果你愿意,我可以:
你现在是零基础吗?