搜尋

首頁  >  問答  >  主體

macos - 为什么mac上C++编译不提示错误?

  1. 我在mac上使用sublime text编译c++程序,当程序有错时,编译器会完全没有提示。请问该如何获得提示?
    比如:我在第二个printf中故意输错result,cmd+B编译后,完全没有反应,也不提示。


如果输入正确,结果如下:

高洛峰高洛峰2874 天前480

全部回覆(2)我來回復

  • 巴扎黑

    巴扎黑2017-04-17 13:24:02

    你的 sublimetext 的 build system 沒設定好

    點Tools->Build System-> new Build system, 複製下面的程式碼進去然後儲存,名字就叫c++11好了. 然後你就可以在build system 裡面選擇你剛才建立的c++11 .

    PS: 這個腳本不只會編譯而且會自動 run

    {
     "cmd": ["g++", "-std=c++0x", "${file}", "-o", "${file_path}/${file_base_name}"],
     "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
     "working_dir": "${file_path}",
     "selector": "source.c, source.c++",
     "variants":
     [
       {
         "name": "Run",
         "cmd":["bash", "-c", "g++ -std=c++0x '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
       }
     ]
    }

    回覆
    0
  • 阿神

    阿神2017-04-17 13:24:02

    一般方法:

    1. 安裝Xcode

    2. 開啟Terminal

    3. cd到cpp所在目錄

    4. 輸入 clang++ name.cpp 編譯

    5. 輸入 ./a.out 運行

    回覆
    0
  • 取消回覆