我最近在我的 Mac 上安装了 xcode 命令行工具。其操作系统版本为 10.9.5。为了测试 g++ 编译器,我创建了一个简单的“hello world”c++ 程序,将其命名为 program.cpp 并将其放在我的桌面上:
#include <iostream>
using namespace std;
int main()
{
cout<<“Hello World”;
return 0;
}
然后我打算创建一个编译版本的 program.cpp,打开终端,将我的目录更改为桌面并键入以下命令:
g++ -o program program.cpp
我收到以下编译错误:
program.cpp:7:11: error: non-ASCII characters are not allowed outside of
literals and identifiers
cout<<“Hello World”;
^
program.cpp:7:14: error: use of undeclared identifier 'Hello'
cout<<“Hello World”;
^
program.cpp:7:25: error: non-ASCII characters are not allowed outside of
literals and identifiers
cout<<“Hello World”;
^
3 errors generated.
这是命令行工具的问题还是其他问题?任何帮助将不胜感激。
最佳答案
您没有使用双引号字符:
“Hello World”
不同于:
"Hello World"
我猜这是由于从 PDF 或其他东西复制粘贴所致,因为像 Word 这样的程序喜欢将“”更改为“”。
此外,如果您使用的是 Xcode 命令行工具,那么您实际上使用的是 clang 而不是 g++。
关于c++ - g++ 编译器在终端中给出奇怪的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33920854/