c++中mfc写文件 把信息写入文件不覆盖原来的内容
CFilefile;file.Open("d:\\mytxt\\myfile.txt",CFile::modeCreate|CFile::modeWrite);CStri...
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();
我的怎么把以前的内容给覆盖了 大侠帮忙啦 展开
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();
我的怎么把以前的内容给覆盖了 大侠帮忙啦 展开
展开全部
加一个追加标志。
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 guarantees the file to open, either as a newly created file or as an existing file. This might be useful, for example, when opening a settings file that may or may not exist already. This option applies to CStdioFile as well.
CFile::modeRead Opens the file for reading only.
CFile::modeReadWrite Opens the file for reading and writing.
CFile::modeWrite Opens the file for writing only.
CFile::modeNoInherit Prevents the file from being inherited by child processes.
CFile::shareDenyNone Opens the file without denying other processes read or write access to the file. Create fails if the file has been opened in compatibility mode by any other process.
CFile::shareDenyRead Opens the file and denies other processes read access to the file. Create fails if the file has been opened in compatibility mode or for read access by any other process.
CFile::shareDenyWrite Opens the file and denies other processes write access to the file. Create fails if the file has been opened in compatibility mode or for write access by any other process.
CFile::shareExclusive Opens the file with exclusive mode, denying other processes both read and write access to the file. Construction fails if the file has been opened in any other mode for read or write access, even by the current process.
CFile::shareCompat This flag is not available in 32-bit and 64-bit MFC. This flag maps to CFile::shareExclusive when used in CFile::Open.
CFile::typeText Sets text mode with special processing for carriage return–linefeed pairs (used in derived classes only).
CFile::typeBinary Sets binary mode (used in derived classes only).
CFile::osNoBuffer The system opens a file with no system caching. For more information see FILE_FLAG_NO_BUFFERING in CreateFile in the Windows SDK.
CFile::osWriteThrough The system writes through any intermediate cache and goes directly to disk. For more information see FILE_FLAG_WRITE_THROUGH in CreateFile in the Windows SDK.
CFile::osRandomAccess A file is accessed randomly. The system can use this as a hint to optimize file caching.
CFile::osSequentialScan A file is accessed sequentially from beginning to end. The system can use this as a hint to optimize file caching. For more information see FILE_FLAG_SEQUENTIAL_SCAN in CreateFile in the Windows SDK.
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 guarantees the file to open, either as a newly created file or as an existing file. This might be useful, for example, when opening a settings file that may or may not exist already. This option applies to CStdioFile as well.
CFile::modeRead Opens the file for reading only.
CFile::modeReadWrite Opens the file for reading and writing.
CFile::modeWrite Opens the file for writing only.
CFile::modeNoInherit Prevents the file from being inherited by child processes.
CFile::shareDenyNone Opens the file without denying other processes read or write access to the file. Create fails if the file has been opened in compatibility mode by any other process.
CFile::shareDenyRead Opens the file and denies other processes read access to the file. Create fails if the file has been opened in compatibility mode or for read access by any other process.
CFile::shareDenyWrite Opens the file and denies other processes write access to the file. Create fails if the file has been opened in compatibility mode or for write access by any other process.
CFile::shareExclusive Opens the file with exclusive mode, denying other processes both read and write access to the file. Construction fails if the file has been opened in any other mode for read or write access, even by the current process.
CFile::shareCompat This flag is not available in 32-bit and 64-bit MFC. This flag maps to CFile::shareExclusive when used in CFile::Open.
CFile::typeText Sets text mode with special processing for carriage return–linefeed pairs (used in derived classes only).
CFile::typeBinary Sets binary mode (used in derived classes only).
CFile::osNoBuffer The system opens a file with no system caching. For more information see FILE_FLAG_NO_BUFFERING in CreateFile in the Windows SDK.
CFile::osWriteThrough The system writes through any intermediate cache and goes directly to disk. For more information see FILE_FLAG_WRITE_THROUGH in CreateFile in the Windows SDK.
CFile::osRandomAccess A file is accessed randomly. The system can use this as a hint to optimize file caching.
CFile::osSequentialScan A file is accessed sequentially from beginning to end. The system can use this as a hint to optimize file caching. For more information see FILE_FLAG_SEQUENTIAL_SCAN in CreateFile in the Windows SDK.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询