search

Home  >  Q&A  >  body text

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

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


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

高洛峰高洛峰2803 days ago444

reply all(2)I'll reply

  • 巴扎黑

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

    Your sublimetext build system is not set up properly

    Click Tools->Build System-> new Build system, copy the code below and save it. The name will be c++11. Then you can select the c++ you just created in the build system. +11.

    PS: This script will not only compile but also run automatically

    {
     "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}'"]
       }
     ]
    }

    reply
    0
  • 阿神

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

    General method:

    1. Install Xcode

    2. Open Terminal

    3. cd to the directory where cpp is located

    4. Input clang++ name.cpp Compile

    5. Enter ./a.out to run

    reply
    0
  • Cancelreply