How to compile and run C/C++ in a Unix console/Mac terminal?

前端 未结 16 1682
抹茶落季
抹茶落季 2020-11-30 16:32

How can I compile/run C or C++ in Unix console or a Mac terminal?

(I know it, forget it, and relearn it again. Time to write it down.)

16条回答
  •  被撕碎了的回忆
    2020-11-30 16:49

    To compile C or C++ programs, there is a common command:

    1. make filename

    2. ./filename

    make will build your source file into an executable file with the same name. But if you want to use the standard way, You could use the gcc compiler to build C programs & g++ for c++

    For C:

    gcc filename.c
    
    ./a.out
    

    For C++:

    g++ filename.cpp
    
    ./a.out
    

提交回复
热议问题