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

  • C/C++
  • Thread starter chemistry1
  • Start date
  • Tags
    C++
In summary, I think that I might have to use c++11 to compile my code.Thanks!In summary, the problem is that the code includes a string, and the compiler is not able to find the string when it tries to compile the code.
  • #1
chemistry1
108
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
  • #2
Try

Code:
    string nom;
    cout << "Vous avez quel age ?";
    getline(cin, nom);
 
  • #3
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.
 
  • #4
Im using windows and code block. And I am the administrator
 
  • #5
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.
 
  • #6
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.
 
  • #7
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 teh 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.
 
  • #8
What would be the suggestion ?
 
  • #9
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 'cout', '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.
 

1. What does "Permission denied" mean in C++?

"Permission denied" in C++ means that the current user does not have the necessary permissions to perform a certain operation or access a certain resource. This could be due to the user's role or privileges, the operating system's security settings, or the specific code implementation.

2. How can I fix a "Permission denied" error in my C++ code?

To fix a "Permission denied" error in C++, you can try adjusting the permissions of the file or resource you are trying to access, or running the program as an administrator. You can also review your code to ensure that the necessary permissions are being requested and handled properly.

3. Can "Permission denied" errors be caused by external factors?

Yes, "Permission denied" errors in C++ can also be caused by external factors such as network or server issues, file system limitations, or conflicts with other programs. It is important to consider these possibilities when troubleshooting the error.

4. Are there any specific C++ functions or commands that commonly result in "Permission denied" errors?

There is no specific C++ function or command that always results in a "Permission denied" error. However, certain actions such as reading or writing to a file, accessing a protected resource, or executing system commands may require specific permissions and can potentially trigger the error.

5. Can I prevent "Permission denied" errors in my C++ code?

To prevent "Permission denied" errors in your C++ code, it is important to understand the permissions and security settings of the operating system and any external resources being accessed. You can also implement proper error handling and permission checking in your code to handle potential errors and prevent crashes.

Similar threads

  • Programming and Computer Science
2
Replies
39
Views
3K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
6
Views
8K
  • Programming and Computer Science
Replies
30
Views
2K
  • Programming and Computer Science
3
Replies
70
Views
3K
  • Programming and Computer Science
2
Replies
65
Views
5K
  • Programming and Computer Science
Replies
32
Views
2K
  • Programming and Computer Science
3
Replies
73
Views
4K
  • Programming and Computer Science
Replies
14
Views
4K
Back
Top