Alexis J. Alexis J. - 15 days ago 5
C++ Question

Having problems compiling my first C++ program

I tried compiling the following program on XCode on my Mac, and I get these errors:

*Non-ASCII charactes are not allowed outside of literals and identifiers. Fix it: Delete ""
*Use of undeclared identifier 'Hello'

#include <iostream>
using namespace std;

int main()
{
cout << “Hello there world!”;
return 0;
}


This program is literally verbatim from the textbook, "A First Book of C++: An Introduction to Programming" so I'm not sure why it would not work. Is this a Mac vs. PC issue?

Answer

The "pretty quotes" copied from your textbook are not valid characters.

Change:

cout << “Hello there world!”;
//      ^                  ^ These characters are not correct.

To:

cout << "Hello there world!";

The editor you use to type code must not be one that replaces the characters you type with characters that might look nicer.