austinstout
austinstout

Reputation: 1220

Very basic C++ issue (expected expression)?

I have just started C++ and I'm not really sure what I am doing, but so far I have some "hello world" code from a tutorial.

   #include <iostream> 

//i only put this first line from users telling me to, it wasn't part of the original post. edited..


int main () {
    std::cout << "Hello, World!\n";
    return 0;
}

The compiler (Xcode for mac) says that there is an 'unexpected expression' right before the cout part of the code. I have no idea how to fix this problem. Can anyone help?

Upvotes: 2

Views: 9095

Answers (2)

Mike Seymour
Mike Seymour

Reputation: 254661

You need to include the header that declares cout:

#include <iostream>

If you still encounter an error after fixing that, then it must be caused by something in "ViewController.h".

Update: Also make sure the compiler recognises this as C++ by making sure the file extension is one of .cc, .cxx or .cpp (or .mm for Objective-C++.)

Upvotes: 7

ap-osd
ap-osd

Reputation: 2834

As mentioned by the earlier contributors, you will need to #include <iostream> which will provide the implementation for std::cout. For a simple hello world C++ program, you don't need #include "ViewController.h" (not sure what it is because it is not a standard include).

Why don't you remove the #include "ViewController.h" and then post the error that you are seeing? I'm sure folks here will be able to help you out.

Upvotes: 1

Related Questions