c++ - Why does ofstream sometimes create files but can't write to them? -


I am trying to use the off-class class to write some stuff in the file, but whatever happens File is created, and then nothing. I have some bus code:

  #include & lt; Iostream & gt; #include & lt; Fstream & gt; # Include & lt; Cstring & gt; # Include & lt; Cerrno & gt; # Include & lt; Time.h> using namespace std; Int main (int argc, char * argv []) {ofstream file; File.open ("test.txt"); If (! File) {cout & lt; & Lt; Strerror (error) & lt; & Lt; Endl; } And {cout & lt; & Lt; "All are fine!" & Lt; & Lt; Endl; } For (int i = 0; i  

When I make a console application, everything is fine, so I'm afraid the code is not fully representative. However, I am using code in a very big project like this - to be honest - I do not fully understand (neorostim). I should write some classes that have been compiled for a DLL which can be loaded by Neurostim.

When code is run, "test.txt" is created and then "no error!" Printed because it is clearly output from the thrower. Obviously this is wrong but. This application runs completely otherwise, and is not staged by the fact that I am trying to write a corrupt stream. It just does not seem to be that there is no problem with permissions, because the file is actually created.

Do anyone have any idea what types of things can be the reason for this strange behavior? (I'm on WinXP Pro SP3 and using Visual C ++ 2008 Express Edition)

Thanks!

Just a thought: - Are you reusing your stream object in your real code? ?

If so, then you need to make sure that you call the stream before reuse the item otherwise, if there is a previous error situation, then it will not work as I Remember, there should be a blank file on this type of stream without calling clear () that can not be written, as you say in your question.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -