在Mac上编译运行C++

xiaoxiao2021-02-28  143

Mac 上自带了g++编译器, 因此只要在命令行(终端)上输入g++, 就会得到反馈

$ g++ clang: error: no input files

接下来写一个HelloWorld.cpp文件

#include <iostream> int main() { using namespace std; cout << "hello world" << endl; return 0; }

在命令行中编译,这里需要在在HelloWorld.cpp的目录中使用该命令,或者是把HelloWorld.cpp的路径带上。通过-o可以生产具体文件名的(.out)文件,否则默认在同一级目录下生成a.out

$ g++ HelloWorld.cpp

最后, 运行生成的.out文件,结果会输出hello world

$ ./a.out hello world
转载请注明原文地址: https://www.6miu.com/read-26096.html

最新回复(0)