syntax errors g++ compiler

1
2
3
4
5
6
#include<iostream>
using namespace std;
int main()
{
return 0;
}


this should be enough tokens for a program to compile and execute.
It compiles but return errors when executed it returns these errors

./test2.cpp: line 2: using: command not found
./test2.cpp: line 3: syntax error near unexpected token `('
./test2.cpp: line 3: `int main()'

I should mention I am using mandriva linux using gedit to write the code and the g++ compiler
so this is pretty much cml.

I'm just confused as to these syntax errors
It seems that you're trying to "run" this as a shell script.
That won't work, you have to invoke g++ to make a binary out of your source code, which you can then execute.
point me toward a tutorial maybe ?

i compiled with the command g++ test2.cpp
no errors
i also can see the a.out file
tutorial tell me after i change permissions (chmod u+x)
i should just be able to type test2.cpp or a.out and it will execute but that returns command not found error
so I tried a ./test.cpp
and the errors were returned
Last edited on
because I want to learn this way

You can't execute C++ source code directly.
You need to type ./a.out
./a.out worked ...

I'm new to linux , on and off for about a year
I've dabbled in this before it just seems a little different than how i was doing it under ubuntu


but many thankies
Topic archived. No new replies allowed.