首页 > 为什么mac上C++编译不提示错误?

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

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


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


一般方法:

  1. 安装Xcode

  2. 打开Terminal

  3. cd到cpp所在目录

  4. 输入 clang++ name.cpp 编译

  5. 输入 ./a.out 运行


你的 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}'"]
   }
 ]
}
【热门文章】
【热门文章】