編寫/編譯 CPP 程序

不適用編譯器,如果創建/運行 CPP程序


1、創建並保存CPP 文件;

#include <iostream>

int main(int argc, const char * argv[]) {
    // insert code here...
    std::cout << "Hello, World!\n";
    return 0;
}

我的文件叫做 test01.cpp,在 Test01 文件夾下面。


2、然後通過命令編譯成 exec 文件。

 $ cd /Users/sysit/MacOSExec/CPPDemos/Test01 
Test01 $ g++  test01.cpp

3、運行 exec 文件

$ ./a.out
Hello, World!

直接運行 $ a.out 會報錯 -bash: a.out: command not found
拖拽文件到終端,可以運行成功


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章