3

I'm a bit of a newbie to C++, but I have some programming experience. I made a basic program, following a guide I found on t'internet. It compiled with g++ easily, but when I ran it it threw these errors:

./FP.cpp: line 1: //: Is a directory ./FP.cpp: line 3: using: command not found ./FP.cpp: line 5: syntax error near unexpected token (' ./FP.cpp: line 5:int main ()'

I'm using Geany on a Raspberry Pi (but using a command line to run the program as the Geany interpreter doesn't work). Here's the program:

    // First program in c++
    #include <iostream>
    using namespace std;

    int main()
    {
    cout << "Hello World!";
    return 0;
    }

Any ideas?

Cheers!

4

2 回答 2

7

It looks like you're trying to execute the source file, i.e. run it as a shell script.

To compile your program you would do something like this:

$ g++ -Wall FP.cpp -o FP

This produces an executable named FP. So you should now see both the original program, FP.cpp, and the executable, FP, in your current directory.

To run the executable (compiled program):

$ ./FP
于 2012-11-07T10:24:06.510 回答
2

Calling ./FP.cpp tries to execute the source code, which is not what you want. You need to compile it via g++, and then run the executable (usually ./FP)

于 2012-11-07T10:24:59.990 回答