1、用vim写第一个C++程序
(1) 打开mac终端
(2)用vim新建一个test.cpp文件
vim test.cpp
(3) 写hello word代码
输入插入命令
i
写入代码
#include <stdio.h> int main() { /* 我的第一个 C 程序 */ printf("Hello, World! \n"); return 0; }
保存代码,输入下面命令
:x
(4)用g++编译成test可执行文件
输入下面命令,不要忘记是g++,不是gcc
g++ test.cpp -o test
如果出现下面报错 bogon:Music a1111$ g++ test.cpp -o test xcode-select: note: no developer tools were found at '/Applications/Xcode.app', requesting install. Choose an option in the di alog to download the command line developer tools. mac会自动安装程序,我们需要耐心等待就行~或者xcode-select --install
(5)执行test文件
输入下面命令
./test
(6) 展示结果