-
January 6th, 2010, 09:49 PM
#1
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.
-
January 6th, 2010, 09:52 PM
#2
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?
-
January 6th, 2010, 10:09 PM
#3
Re: ofstream not working for the released version.
Originally Posted by ninja9578
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++.
-
January 7th, 2010, 12:57 AM
#4
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.
-
January 7th, 2010, 11:01 AM
#5
Re: ofstream not working for the released version.
Do you have any VC++ specific code, can you try compiling using GCC?
-
January 7th, 2010, 06:38 PM
#6
Re: ofstream not working for the released version.
Originally Posted by clonebull
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
-
January 7th, 2010, 09:07 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|