C++ Hello World not compiling

C++ Hello World not compiling

本文关键字:compiling not World Hello C++      更新时间:2023-10-16

我最近刚安装了OSX lion并安装了xcode 4。

我在某个目录下创建了一个文件,并将以下代码放入其中:

#include <iostream>
using namespace std;
int main()
{
  cout << "Hello World!";
  return 0;
}

然后我运行gcc filename.cc

我得到这些错误:

1。cc:3:20: error: iostream: No such file or directory1.在函数' int main() '中:1.Cc:8: error: ' cout '未在此范围内声明

怎么了?

编辑:

如果我运行g++ filename。我得到相同的错误。

1。cc:3:20: error: iostream: No such file or directory1.在函数' int main() '中:1.Cc:8: error: ' cout '未在此范围内声明

为什么使用gcc?

看起来您的包含路径没有设置,所以没有找到iostream。这些通常是自动设置的—您需要像INCLUDE=

这样的环境变量

或者您可以在命令行中设置这些,如

g++ -i filename.cc

试试这个:

g++ filename.cc

你也可以尝试使用clang++,它将使用苹果的新编译器:

clang++ filename.cc