Pergunta

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!

Foi útil?

Solução

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

Outras dicas

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)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top