简体   繁体   中英

g++ Compiler Giving Strange Errors in Terminal

I recently installed xcode command line tools on my Mac. Its OS is version 10.9.5. To test out the g++ compiler I created a simple "hello world" c++ program, called it program.cpp and put it on my desktop:

#include <iostream>

using namespace std;

int main()
{
    cout<<“Hello World”;
    return 0;
}

Then I intended to create a compiled version of program.cpp, opened terminal, changed my directory to the desktop and typed the following command:

g++ -o program program.cpp

I received the following compilation errors:

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.

Is this a problem with the command line tools or something else? Any help would be appreciated.

You aren't using double quote characters:

“Hello World”

is not the same as:

"Hello World"

I guess this is due to a copy-and-paste from PDF or something, as programs like Word like to change "" to “”.

Also if you are using the Xcode Command Line tools, you are actually using clang and not g++.

There might be an "US International - PC" input method set on your mac (assuming you are on mac) and that has accented characters which result in '“' being inserted when you expected '"'.

enter link description here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM