You are not logged in.
Hi all, just starting out in C++ again after a few years and having some issues.
I'm getting errors trying to run a simple hello world app, it compiles ok by the looks of it but I get an error when trying to run it.
my code is as follows (filename hi.cpp):
#include <iostream>
int main()
{
using namespace std;
cout << "hello world";
cout << endl;
return 0;
}
I compile the file as follows:
cpp hi.cpp -o hi
This seems to compile ok, so I chmod +x hi and then try to run ./hi then get the following:
./hi: line 64: syntax error near unexpexted token `('
./hi line 64: `namespace std __attribute__ ((__visability__ ("default"))) {'
My geese is that I may not have installed some required components but do not now what.
Last edited by astacha (2010-01-10 15:00:37)
Offline
cpp is the c preprocessor. It processes the source file before compilation, dealing with macros, includes, etc. You need to compile your program with g++
g++ hi.cpp -o hi
There will then be no need to chmod the resulting file. Also, I've never seen "using namespace std" placed inside of main, although it appears to be legal. I'd also recommend the -Wall flag to g++, it will warn you about potential errors in your code.
Offline
You have it compile it as
g++ h1.cpp -o h1
Oops late.
Last edited by bharani (2010-01-10 11:34:35)
Tamil is my mother tongue.
Offline
Thank you for that. That'll teach me for skipping over the parts I think I remember and reading the book properly.
Offline