Why am I getting a Permission denied error when compiling my c++ code?

  • Context: C/C++ 
  • Thread starter Thread starter chemistry1
  • Start date Start date
  • Tags Tags
    C++
Click For Summary
SUMMARY

The user encountered a "permission denied" error while compiling C++ code using Code::Blocks on Windows. The issue arose when attempting to execute the output file, resulting in the disappearance of the .exe file. Solutions included running Code::Blocks as an administrator, checking the properties of the output directory for permissions, and ensuring that the C++11 standard was enabled in the compiler settings. The user resolved the issue by creating a new project and including the necessary headers, specifically #include <string>.

PREREQUISITES
  • Basic understanding of C++ programming
  • Familiarity with Code::Blocks IDE
  • Knowledge of Windows operating system file permissions
  • Understanding of C++11 features and compiler settings
NEXT STEPS
  • Learn how to manage file permissions in Windows
  • Explore C++11 features and their benefits
  • Investigate common C++ compilation errors and their resolutions
  • Practice creating and managing projects in Code::Blocks
USEFUL FOR

Beginner C++ programmers, students learning to compile code, and developers troubleshooting compilation issues in Code::Blocks on Windows.

chemistry1
Messages
108
Reaction score
0
Hi, I'm having a serious trouble when I compile my code :

Code:
#include <iostream>

using namespace std;

int main()
{
string nom("x");
cout << "Vous avez quel age ?";
cin >> nom;
cout << "Vous avez-vous donc" << nom << "ans?" ;
return 0 ;
}

Here's the resume ; I click on compile&run and my console do open, but it doesn't execute the code.(nothing happens.) I CLOSE the console and re click on compile & run, but this time, an error shows up saying : 1d.exe , cannot open output file bin\Debug\test.exe permission denied. And that's not all, because the .exe has totally disapeared. So, basically, I can't run anything and need to delete my file and recreate a new one. The moment I add this code, the same thing happens. I have no idea what to do. (By the way, I just began learning.)

thanks !
 
Technology news on Phys.org
Try

Code:
    string nom;
    cout << "Vous avez quel age ?";
    getline(cin, nom);
 
chemistry1 said:
Hi, I'm having a serious trouble when I compile my code :

Code:
#include <iostream>

using namespace std;

int main()
{
string nom("x");
cout << "Vous avez quel age ?";
cin >> nom;
cout << "Vous avez-vous donc" << nom << "ans?" ;
return 0 ;
}

Here's the resume ; I click on compile&run and my console do open, but it doesn't execute the code.(nothing happens.) I CLOSE the console and re click on compile & run, but this time, an error shows up saying : 1d.exe , cannot open output file bin\Debug\test.exe permission denied. And that's not all, because the .exe has totally disapeared. So, basically, I can't run anything and need to delete my file and recreate a new one. The moment I add this code, the same thing happens. I have no idea what to do. (By the way, I just began learning.)
What operating system are you running? From what your wrote, I'm guessing you might be using Visual Studio on Windows. If you're getting a permission denied error, try starting Visual Studio as an administrator.
 
Im using windows and code block. And I am the administrator
 
After the program locks up, try running task manager, go to process and see if test.exe is still running. Not likely, but could the issue be the name? Try something other than "test.exe".

I assume that bin\debug\... directory exists?

You could try visual c++ express (it's free) to see if you have the same problem.
 
If bin\debug directory exists, check the properties of this directory to see if you as an admin have permissions (particularly execute permission) there. If not, you can add yourself. That should take care of the permission problem.
 
chemistry1 said:
it doesn't execute the code.(nothing happens.)

"Doesn't execute" doesn't follow form "nothing happens". Can be program does execute, just didn't reach the code showing anything on the screen.

I CLOSE the console and re click on compile & run, but this time, an error shows up saying : 1d.exe , cannot open output file bin\Debug\test.exe permission denied.

That could mean old process is still running, file is locked and it is not possible to replace it with a new copy of freshly compiled exe.
 
What would be the suggestion ?
 
You already got several, have you tried any of them?

Have you checked if something simple, like

Code:
#include <iostream>

using namespace std;

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

works?
 
  • #10
Well, yes it does work, but only if I do not put my code in before. If I do, forget it, nothing works anymore and I need to delete my file and create a new one so things begin working again. (My .exe goes somewhere else.)

Also, I think string nom("x"); might be a problem. I've should have putten char('x') since it's only one character.
 
  • #11
You were told to try to declare it as just
Code:
string nom;

You don't need to init it with a value (be it string "x" or a single character 'x').
 
  • #12
Ok good, I created a new project and did what you asked. It works. ( It didn't in my non working file)

Could you explain me what happened exactly ? ... I'm in the learning phase, so I don't know much. WHy did my things stop working with what I wrote ? thanks
 
  • #13
Don't you have to use also:

Code:
#include <string>

?
 
  • #14
Well, I don't know, haven't seen it. I barelly begun, it's been 2 weeks xD What does it exactly do ?
 
  • #15
Try this

Code:
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string nom;
    cout << "Vous avez quel age ? ";
    getline(cin, nom);
    cout << "Vous avez-vous donc " << nom << " ans?" << endl ;
    return 0 ;
}
 
  • #16
Oh, it looks like my problem has stopped. Someone has suggested me that my c++11 was maybe disabled. He told me to go to the compiler settings and put it to std=c++11 and guess what, it worked ! But still, I find it weird that a syntax problem could cause all this mess...
 
  • #17
chemistry1 said:
What does it exactly do ?

'#include <string>' gives you access to the 'string' data type and its associated operations, like '#include <iostream>' gives you access to 'count', 'getline", the '>>' operator for stream output, etc.

I'd expect that trying to declare a 'string' variable without first doing #include <string>' would give you a compiler error message. Maybe this has changed in more recent versions of C++ than the ones I've used.
 

Similar threads

  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 39 ·
2
Replies
39
Views
5K
  • · Replies 6 ·
Replies
6
Views
12K
Replies
12
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
Replies
7
Views
2K
  • · Replies 70 ·
3
Replies
70
Views
5K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K