I've just started learning C++ on Linux. I have written a very small program which compiles but I get run time errors everytime I run it. The code is shown below:


int DoubleOf(int n);

int main() {
    std::cout << "Double of 5 is " << DoubleOf(5);
    return 0;

int DoubleOf(int n) {
    return n+n;

I compile it using g++ main.cpp -o main.out, without any errors but when I run it, sh main.out, it outputs:
main.out: 3: main.out: Syntax error: Unterminated quoted string

Any help is appreciated.

Recommended Answers

All 2 Replies

Check this out.

It seems to me that you have a problem on your PATH variable.

gcc produces a binary executable, not a shell script. To run it, type ./main.out.

commented: Really stupid of me... thank you so much +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.