CFile::modeNoTruncate
来源:互联网 发布:矩阵在密码学中的应用 编辑:程序博客网 时间:2024/05/01 22:40
CFile::modeNoTruncate 参数详细说明
MSDN上说到:
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. 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.
意思是,用modeCreate模式创建和打开一个文件,假如这个文件已经存在,则会清空这个已经存在的文件,加上modeNoTruncate的话,就不会清空这个文件了。举个例子,如果原来文件长80K的话,而你要写50K的数据。用一般的modeCreate,先会把文件长度重置为0,再写入50K数据,最后文件长度为50K用CFile::modeNoTruncate的话,直接写入50K数据,最终文件长度还是80K。数据为前部分50K新数据和后部30K旧数据。
在MFC中,追加数据也比较简单,好像设定CFile::modeNoTruncate参数就可以了。这个例子在CStdioFile类进行文件操作,读写等。可是,看了下好像没有简单的方法,于是在网上看到这样的写法:
CStdioFile file(strFile,CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite);
file.WriteString(strTmp);
file.Close;
modeNoTruncate的意思就是不要截取的意思吧
可是,试了下这段代码,并没有起作用,不知道是什么原因。
于是,在WriteString写字符串之前加了个把指针先定位到文件末尾的代码,就可以了
CString strTmp="hehe\r\n";
CStdioFile file(strFile,CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite);
file.SeekToEnd();//先定位到文件尾部
file.WriteString(strTmp);
file.Close();
- CFile::modeNoTruncate
- CFile参数modeNoTruncate
- CFile::modeNoTruncate 参数详细说明
- CFile 深入研究之 CFile::modeNoTruncate
- CFile...
- CFile
- CFile
- CFile
- CFile
- CFile
- CFile
- CFile
- CFile
- CFile
- CFile
- CFile
- CFile
- CFile
- PyCharm 教程(五)断点 调试
- Nginx和PHP-FPM的启动/重启脚本
- linux杀死进程的简单讲解
- Wsgi研究
- 调用父类的带参数的构造函数
- CFile::modeNoTruncate
- 黑马程序员_Java高新技术之反射 Constructor类
- android 启动过程分析
- log4j最佳配置备份
- LINUX内核经典面试题
- 获取咕咚运动移动应用中的数据——非官方API
- Ubuntu 12.04 创建源服务器
- django 正则表达式
- C++中const理解