1

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.

Orren Ravid
  • 560
  • 1
  • 6
  • 24

2 Answers2

3

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++.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • I was typing the code in text edit but I wasn't aware of the double quote character problem. I'll try it again in atom. As for the for the g++ clang discrepancy, I tried both on someone else's mac and both worked. So that probably isn't the problem. – Orren Ravid Nov 25 '15 at 15:59
  • If English is not your first language, then you probably know more about how these issues can occur than I do. The clang remark was not related to the issue, as such, but you need to be aware that you aren't actually using a GNU product (type `g++ --version`, for example). – trojanfoe Nov 25 '15 at 16:02
  • @OrrenRavid Don't write code in TextEdit, or anything else that is meant for writing "normal" text. Use a (programmer's) text editor - there are many to choose from - or an IDE like XCode. – molbdnilo Nov 25 '15 at 16:09
  • Thanks that's good to know. I will try to resolve my problem using a different text editor and choose this answer once the problem is resolved. – Orren Ravid Nov 25 '15 at 16:09
  • That appeared to be the problem. I switched to a "atom" a text editor for programming languages and it compiled correctly. – Orren Ravid Nov 25 '15 at 18:57
0

There might be an "U.S. 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

Community
  • 1
  • 1
Vasiliy
  • 674
  • 6
  • 5