1

Every time I try to execute a program, no matter what program, I get this message:

bash: ./filename.cpp: Permission denied

When I compile I have no problems, it works fine. But when I want to execute I get this message.

Does it have anything to do with permissions? Because I'm having a lot of problems with this, too. I can't access my shared folders, unless I use

sudo nautilus

Please see my other question.

Francesca
  • 19
  • 1
  • 2

1 Answers1

5

To compile and run a .cpp file in Ubuntu, follow this example guide

First we need a .cpp file, we will save it as main.cpp and in home/user/documents

#include <iostream>
using namespace std;

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

If you need it install g++

sudo apt-get install g++

Now we have an program, we can go to Home/user/documents and compile it

cd ~/Documents
g++ main.cpp 

This will produce a file named a.out in your /home/user/Documents directory

Now run the a.out

./a.out

Output will be

Hello World!
Mark Kirby
  • 18,949
  • 19
  • 79
  • 116