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

前端 未结 16 1600
抹茶落季
抹茶落季 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:55

    This is the command that works on all Unix machines... I use it on Linux/Ubuntu, but it works in OS X as well. Type the following command in Terminal.app.

    $ g++ -o lab21 iterative.cpp
    

    -o is the letter O not zero

    lab21 will be your executable file

    iterative.cpp is your c++ file

    After you run that command type the following in terminal to run your program:

    $ ./lab21
    

提交回复
热议问题