C++ cannot write simple text file

Sysprogs forums Forums VisualGDB C++ cannot write simple text file

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #7608
    jburrus
    Participant

    Hello,

    The following C++ test code should write a simple txt file in a specified folder in a remote server under CentOS:

    #include <fstream>
    #include <string>
    int main(int argc, char* argv[])
    {
     std::string content = "This is a test content.";
     std::string filename = "/myFolder/myFile.txt";
     std::ofstream file;
     file.open(filename.c_str());
     file << content;
     file.close();
    return 0;
    }

    It compiles and works properly in gcc 5.3.1. While it does compile using VisualGDB, it surprisingly does not write actually the file.

    The following post in stackoverflow (http://stackoverflow.com/questions/16779149/c-program-in-xcode-not-outputting-simple-text-file-using-outfile) seems to mention a similar issue in Xcode. It suggests this is merely a setting in VisualGDB.

    How to set up VisualGDB in order to fix this problem?

    Thank you for your time.

    Jacques Burrus

    #7612
    support
    Keymaster

    Hi,

    Most likely either your user account does not have access to the directory where you are trying to create the file, or you are running it on a wrong machine. Please try to change the directory of the file to /tmp and if it does not help, try running the executable directly over SSH.

    #7615
    jburrus
    Participant

    Hi Bazis.

    Thank you for your reply. The mistake was indeed the access and changing the corresponding settings solved the problem.

    Regards,

    Jacques Burrus

    #7629
    support
    Keymaster

    No problem. If you encounter further problems, feel free to create a new thread.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.