Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Permission denied ? c++

  1. Jun 14, 2013 #1
    Hi, I'm having a serious trouble when I compile my code :

    Code (Text):
    #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 !
     
  2. jcsd
  3. Jun 14, 2013 #2

    rcgldr

    User Avatar
    Homework Helper

    Try

    Code (Text):

        string nom;
        cout << "Vous avez quel age ?";
        getline(cin, nom);
     
     
  4. Jun 14, 2013 #3

    Mark44

    Staff: Mentor

    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.
     
  5. Jun 14, 2013 #4
    Im using windows and code block. And im the administrator
     
  6. Jun 14, 2013 #5

    rcgldr

    User Avatar
    Homework Helper

    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.
     
  7. Jun 14, 2013 #6

    Mark44

    Staff: Mentor

    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.
     
  8. Jun 15, 2013 #7

    Borek

    User Avatar

    Staff: Mentor

    "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.

    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.
     
  9. Jun 15, 2013 #8
    What would be the suggestion ?
     
  10. Jun 15, 2013 #9

    Borek

    User Avatar

    Staff: Mentor

    You already got several, have you tried any of them?

    Have you checked if something simple, like

    Code (Text):

    #include <iostream>

    using namespace std;

    int main()
    {
       cout << "Hello world!";
       return 0 ;
    }
     
    works?
     
  11. Jun 15, 2013 #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.
     
  12. Jun 15, 2013 #11

    Borek

    User Avatar

    Staff: Mentor

    You were told to try to declare it as just
    Code (Text):
    string nom;
    You don't need to init it with a value (be it string "x" or a single character 'x').
     
  13. Jun 15, 2013 #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
     
  14. Jun 15, 2013 #13

    jtbell

    User Avatar

    Staff: Mentor

    Don't you have to use also:

    Code (Text):

    #include <string>
     
    ?
     
  15. Jun 15, 2013 #14
    Well, I don't know, haven't seen it. I barelly begun, it's been 2 weeks xD What does it exactly do ?
     
  16. Jun 15, 2013 #15

    rcgldr

    User Avatar
    Homework Helper

    Try this

    Code (Text):

    #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 ;
    }
     
     
  17. Jun 15, 2013 #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...
     
  18. Jun 15, 2013 #17

    jtbell

    User Avatar

    Staff: Mentor

    '#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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Permission denied ? c++
  1. To C or not to C (Replies: 31)

  2. C or C++? (Replies: 8)

Loading...