g++ 编译器在终端中给出奇怪的错误
g++ Compiler Giving Strange Errors in Terminal
我最近在 Mac 上安装了 xcode 命令行工具。它的 OS 是版本 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++。
您的 mac 上可能设置了 "U.S. International - PC" 输入法(假设您使用的是 mac),该输入法具有重音字符,导致在您输入时插入“”预期 '"'。
enter link description here
我最近在 Mac 上安装了 xcode 命令行工具。它的 OS 是版本 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++。
您的 mac 上可能设置了 "U.S. International - PC" 输入法(假设您使用的是 mac),该输入法具有重音字符,导致在您输入时插入“”预期 '"'。
enter link description here