CStdIOFile ????
-
Hi, I need to open a file and appened to it later, from some reason, it get's overwritten, here is the most simple code....
CStdioFile log_file (_T("file.txt"),CFile::modeWrite |CFile::modeCreate |CFile::typeText); log_file.WriteString("123\n"); ///do something....... CStdioFile log_file (_T("file.txt"),CFile::modeWrite |CFile::typeText |CFile::modeNoTruncate); log_file.WriteString("456\n");
end result in the file is always "456". Why???? -
Hi, I need to open a file and appened to it later, from some reason, it get's overwritten, here is the most simple code....
CStdioFile log_file (_T("file.txt"),CFile::modeWrite |CFile::modeCreate |CFile::typeText); log_file.WriteString("123\n"); ///do something....... CStdioFile log_file (_T("file.txt"),CFile::modeWrite |CFile::typeText |CFile::modeNoTruncate); log_file.WriteString("456\n");
end result in the file is always "456". Why???? -
try to use retrived handle in fopen function with a+ flag instead of recalling constructor 4apai There're no impossible tasks. There're tasks that required infinite period of execution time.
I don't want to use fopen etc.... The reason why I started using CStdioFile is because Visual Studio .NET did not support the anymore
-
I don't want to use fopen etc.... The reason why I started using CStdioFile is because Visual Studio .NET did not support the anymore
-
Hi, I need to open a file and appened to it later, from some reason, it get's overwritten, here is the most simple code....
CStdioFile log_file (_T("file.txt"),CFile::modeWrite |CFile::modeCreate |CFile::typeText); log_file.WriteString("123\n"); ///do something....... CStdioFile log_file (_T("file.txt"),CFile::modeWrite |CFile::typeText |CFile::modeNoTruncate); log_file.WriteString("456\n");
end result in the file is always "456". Why????CFile::modeNoTruncate Combine this value with modeCreate. If the file being created already exists, it is not truncated to 0 length. Thus the file is guaranteed to open, either as a newly created file or as an existing file Artificial intelligence is no match for natural stupidity.
-
Hi, I need to open a file and appened to it later, from some reason, it get's overwritten, here is the most simple code....
CStdioFile log_file (_T("file.txt"),CFile::modeWrite |CFile::modeCreate |CFile::typeText); log_file.WriteString("123\n"); ///do something....... CStdioFile log_file (_T("file.txt"),CFile::modeWrite |CFile::typeText |CFile::modeNoTruncate); log_file.WriteString("456\n");
end result in the file is always "456". Why????Here's whay I do and it works everytime.
CStdioFile myFile; myFile.Open (FileName, CFile::modeCreate | CFile::modeReadWrite | CFile::modeNoTruncate, NULL); myFile.SeekToEnd(); myFile.WriteString (strLSbuf); myFile.Close ();
I think the problem you are running into is that you are not first placing the cursor to the end of the line then writing out your string. So when you do an open on the file, the cursor is placed at the beginning of the line and you overwrite your existing data. Hope this help Tom Wright tawright915@yahoo.com -
CFile::modeNoTruncate Combine this value with modeCreate. If the file being created already exists, it is not truncated to 0 length. Thus the file is guaranteed to open, either as a newly created file or as an existing file Artificial intelligence is no match for natural stupidity.
So.... You suggest to change the second time I open the file to:
CStdioFile log_file (_T("file.txt"),CFile::modeWrite |CFile::typeText ||CFile::modeCreate |CFile::modeNoTruncate);
I already tried that, just like the the microsoft site say, still no change, this is crazy, I know..... -
Here's whay I do and it works everytime.
CStdioFile myFile; myFile.Open (FileName, CFile::modeCreate | CFile::modeReadWrite | CFile::modeNoTruncate, NULL); myFile.SeekToEnd(); myFile.WriteString (strLSbuf); myFile.Close ();
I think the problem you are running into is that you are not first placing the cursor to the end of the line then writing out your string. So when you do an open on the file, the cursor is placed at the beginning of the line and you overwrite your existing data. Hope this help Tom Wright tawright915@yahoo.comAAAAAnnnndddddd.... we have a winner !!! Thanks a lot. When I worked with ofstream, and use the ios::app flag it was done by default I guess. Have a great day.
-
So.... You suggest to change the second time I open the file to:
CStdioFile log_file (_T("file.txt"),CFile::modeWrite |CFile::typeText ||CFile::modeCreate |CFile::modeNoTruncate);
I already tried that, just like the the microsoft site say, still no change, this is crazy, I know.....