Click here to Skip to main content
15,919,434 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Read and write in file Pin
polopo3-Sep-08 20:52
polopo3-Sep-08 20:52 
GeneralRe: Read and write in file Pin
toxcct3-Sep-08 21:29
toxcct3-Sep-08 21:29 
GeneralRe: Read and write in file Pin
cpvc++3-Sep-08 22:04
cpvc++3-Sep-08 22:04 
GeneralRe: Read and write in file Pin
toxcct3-Sep-08 22:07
toxcct3-Sep-08 22:07 
GeneralRe: Read and write in file Pin
cpvc++3-Sep-08 22:13
cpvc++3-Sep-08 22:13 
GeneralRe: Read and write in file Pin
toxcct3-Sep-08 22:15
toxcct3-Sep-08 22:15 
GeneralRe: Read and write in file Pin
cpvc++3-Sep-08 22:26
cpvc++3-Sep-08 22:26 
GeneralRe: Read and write in file [modified] Pin
toxcct3-Sep-08 22:36
toxcct3-Sep-08 22:36 
cpvc++ wrote:
I am not Mr. polop which is start this thread


sorry, I didn't notice that aspect of the things Smile | :)

The problem in your code is that you're using CFile::modeCreate, but according to the documentation[^], this flag tells to truncate the file if already existing :

MSDN says:
CFile::modeCreate
Directs the constructor to create a new file. If the file exists already, it is truncated to 0 length



So, you have to add the flag CFile::modeNoTruncate to counter this undesired behavior.
The use of this flag however keeps the file pointer at the beginning of the file. So if you want to append things at the end, you must call once after CStdioFile::Open() the function CStdioFile::Seek(CFile::end).

Does the following work better ?
CStdioFile file;
<font color="blue">if</font> (file.Open(_T(<font color="blue">"\\log.txt"</font>), CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate)) {
    <font color="green">//file.Seek(0, CFile::end);</font>
    file.SeekToEnd();
    file.WriteString(logfile);
    file.WriteString(_T(<font color="blue">"\n"</font>));
    file.Close();
}



modified on Thursday, September 4, 2008 6:46 AM

GeneralRe: Read and write in file Pin
cpvc++3-Sep-08 23:19
cpvc++3-Sep-08 23:19 
GeneralRe: Read and write in file Pin
toxcct3-Sep-08 23:23
toxcct3-Sep-08 23:23 
GeneralRe: Read and write in file Pin
cpvc++3-Sep-08 23:49
cpvc++3-Sep-08 23:49 
GeneralRe: Read and write in file Pin
toxcct4-Sep-08 0:46
toxcct4-Sep-08 0:46 
GeneralRe: Read and write in file Pin
polopo3-Sep-08 21:56
polopo3-Sep-08 21:56 
Questiongive color to CtabCtrl buttons......... Pin
shaina22313-Sep-08 18:48
shaina22313-Sep-08 18:48 
GeneralPlatform independent library - Suggestions needed Pin
Christian Flutcher3-Sep-08 18:22
Christian Flutcher3-Sep-08 18:22 
AnswerRe: Platform independent library - Suggestions needed Pin
Rajesh R Subramanian3-Sep-08 19:54
professionalRajesh R Subramanian3-Sep-08 19:54 
GeneralRe: Platform independent library - Suggestions needed Pin
Christian Flutcher3-Sep-08 20:53
Christian Flutcher3-Sep-08 20:53 
AnswerRe: Platform independent library - Suggestions needed Pin
Rajesh R Subramanian3-Sep-08 21:04
professionalRajesh R Subramanian3-Sep-08 21:04 
GeneralRe: Platform independent library - Suggestions needed Pin
Christian Flutcher3-Sep-08 22:33
Christian Flutcher3-Sep-08 22:33 
AnswerRe: Platform independent library - Suggestions needed Pin
Rajesh R Subramanian3-Sep-08 22:59
professionalRajesh R Subramanian3-Sep-08 22:59 
GeneralRe: Platform independent library - Suggestions needed Pin
Christian Flutcher3-Sep-08 23:03
Christian Flutcher3-Sep-08 23:03 
GeneralRe: Platform independent library - Suggestions needed Pin
markkuk3-Sep-08 23:16
markkuk3-Sep-08 23:16 
GeneralRe: Platform independent library - Suggestions needed Pin
Christian Flutcher3-Sep-08 23:23
Christian Flutcher3-Sep-08 23:23 
AnswerRe: Platform independent library - Suggestions needed Pin
Rajesh R Subramanian3-Sep-08 23:25
professionalRajesh R Subramanian3-Sep-08 23:25 
AnswerRe: Platform independent library - Suggestions needed Pin
Rajesh R Subramanian3-Sep-08 23:23
professionalRajesh R Subramanian3-Sep-08 23:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.