在 Ubuntu 上学习 C++ 是一个非常常见且高效的选择。下面我按从零开始的思路,分步骤给你讲清楚怎么做。
sudo apt update
sudo apt upgrade
sudo apt install g++
检查是否安装成功:
g++ --version
初学者推荐:
sudo apt install code
或去官网下载 .deb 安装
其他选择:
sudo apt install geany
mkdir cpp_learning
cd cpp_learning
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)if / switch)for / while)vectormapsetsudo apt install gdb
g++ -g hello.cpp -o hello
gdb ./hello
hello: hello.cpp
g++ hello.cpp -o hello
运行:
make
✅ 多写代码,少看视频
✅ 每学一个概念就写一个小例子
✅ 遇到报错先读错误信息
✅ 用 Git 管理代码(git init)
如果你愿意,我可以:
你现在是哪种情况?