在 Ubuntu 上学习 C++ 基础,整体流程很清晰:装环境 → 写代码 → 编译运行 → 系统学习语法。下面按步骤给你一个实用入门路线。
sudo apt update
sudo apt upgrade
sudo apt install g++ build-essential
g++ --version
能看到版本号就说明成功了。
mkdir cpp_learn
cd cpp_learn
nano hello.cpp
#include <iostream>
using namespace std;
int main() {
cout << "Hello, Ubuntu C++!" << endl;
return 0;
}
g++ hello.cpp -o hello
./hello
cin / cout)string 类型sudo snap install code --classic
安装 C++ 插件即可。
g++ main.cpp math.cpp -o app
如果你愿意,我可以: