当前位置: 代码迷 >> 综合 >> mac下用vim编写程序
  详细解决方案

mac下用vim编写程序

热度:32   发布时间:2023-10-26 22:37:11.0

1、用vim写第一个C++程序
       1)  打开mac终端
       2) 用vim新建一个test.cpp文件
    vim test.cpp
       3) 写hello word代码
         输入插入命令 
    i
         写入代码
    #include<iostream>
 
    using namespace std;
 
    int main() {
        cout<<"hello word"<<endl;
        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会自动安装程序,我们需要耐心等待就行

       5)执行test文件
         输入下面命令
         
    ./test