c++中mfc写文件 把信息写入文件不覆盖原来的内容

来源:百度知道 编辑:UC知道 时间:2024/06/28 22:55:13
CFile file;
file.Open( "d:\\mytxt\\myfile.txt", CFile::modeCreate|CFile::modeWrite );

CString str("Sex:male");
//GetDlgItem(IDC_RADIO1)->SetWindowText(str);
file.SeekToEnd();
file.Write( str.GetBuffer(0),str.GetLength() );
file.Close();

我的怎么把以前的内容给覆盖了 大侠帮忙啦

把 CFile::modeCreate 标志去掉

加一个追加标志。
hFile
The HFILE returned from a previous call to CreateFile, as described in the Windows SDK.

lpszFileName
A string that is the path to the desired file. The path can be relative or absolute.

nOpenFlags
Sharing and access mode. Specifies the action to take when opening the file. You can combine options listed below by using the bitwise-OR (|) operator. One access permission and one share option are required; the modeCreate and modeNoInherit modes are optional. The values are as follows:

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

CFile::modeNoTruncate Combine this value with modeCreate. If the file being created already exists, it is not truncated to 0 length. Furthermore, if the file being created already exists, the underlying file pointer will point to the beginning of the file. This flag guarantee