file writing not working after call to open file dialog

后端 未结 2 688
北恋
北恋 2020-12-12 04:56

after call to following function i cant write to any files i tried c++ fstream and c\'s fopen what\'s wrong please help thanks in advance i am using codeblocks mingw windows

相关标签:
2条回答
  • 2020-12-12 05:49

    If you change folder in the dialog it will change the current folder for your process - try adding the OFN_NOCHANGEDIR flag.

    0 讨论(0)
  • 2020-12-12 05:56

    Try CreateFile and WriteFile.

    string s = "file.dat";
    
    HANDLE hFile = CreateFile(s.c_str(),       // name of the write
                       GENERIC_WRITE,          // open for writing
                       0,                      // do not share
                       NULL,                   // default security
                       CREATE_ALWAYS,          // Creates a new file, always
                       FILE_ATTRIBUTE_NORMAL,  // normal file
                       NULL);                  // no attr. template
    DWORD writesBytes;
    bool writeok = WriteFile(hFile, &Current_Doc, sizeof(Current_Doc), &writesBytes, NULL);
    
    CloseHandle(hFile);
    

    Similar problem, and my answer is here:

    OPENFILENAME open dialog

    0 讨论(0)
提交回复
热议问题