CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2009
    Posts
    16

    ofstream not working for the released version.

    I am trying to create/write a txt cfg file. It is working fine in VC++ debugger but after I generated a .exe file. It doesn't work anymore. I also tried adding in the current workpath but still doesn't work. Anyone experienced this problem before? Thanks!
    BTW, the ofstream code is in a dll.

  2. #2
    Join Date
    Jan 2009
    Posts
    1,689

    Re: ofstream not working for the released version.

    Good guess is that you're doing something that's not optimization-safe. What's your code look like?

  3. #3
    Join Date
    Oct 2009
    Posts
    16

    Re: ofstream not working for the released version.

    Quote Originally Posted by ninja9578 View Post
    Good guess is that you're doing something that's not optimization-safe. What's your code look like?
    Thanks for your quick response!

    My simplified code:
    void GenerateConfigFile(char *fileName)
    {
    const char content[] =
    "Config File Content\n\
    .....\n\
    .....\n";

    ofstream outFile(fileName);
    outFile.write(content, strlen(content));
    outFile.close();
    }

    The above code is working fine using under VC++.

  4. #4
    Join Date
    Oct 2009
    Posts
    16

    Re: ofstream not working for the released version.

    I suspect this is a problem related to the built dll. Sorry, maybe this is not a pure C++ problem. Maybe it is a VC++ problem.

  5. #5
    Join Date
    Jan 2009
    Posts
    1,689

    Re: ofstream not working for the released version.

    Do you have any VC++ specific code, can you try compiling using GCC?

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: ofstream not working for the released version.

    Quote Originally Posted by clonebull View Post
    I am trying to create/write a txt cfg file. It is working fine in VC++ debugger but after I generated a .exe file. It doesn't work anymore.
    Please be more specific. What "doesn't work"? Is the file created? Does the code crash?

    Second, you are passing something to that function -- we don't know what that name is since it is a parameter. Maybe that name is garbage in release mode.

    Anytime you suspect there is something wrong with file writing, take a step back and hard-code the file name in the code. Then see if that works. If it works, then the problem is the generation of the name, not the actual opening and closing of the file.

    Regards,

    Paul McKenzie

  7. #7
    Join Date
    Oct 2009
    Posts
    16

    Re: ofstream not working for the released version.

    Thanks for all the suggestions!

    Problem identified.

    The config file reading/writing problem was caused by incorrect path because the current working path changed by GetOpenFileName(). So actually the config file was saved to another folder.

    It was hard for me to debug the dll with .exe. "printf, cout, MessageBox" doesn't work, dont know why. any suggestions?%

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured