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

浏览:39日期:2023-05-20

问题描述

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

macos - 为什么mac上C++编译不提示错误?如果输入正确,结果如下:macos - 为什么mac上C++编译不提示错误?

问题解答

回答1:

你的 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}’'] } ]}回答2:

一般方法:

安装Xcode

打开Terminal

cd到cpp所在目录

输入 clang++ name.cpp 编译

输入 ./a.out 运行

相关文章: