VC语言

本类阅读TOP10

·VC++ 学习笔记(二)
·用Visual C++打造IE浏览器(1)
·每个开发人员现在应该下载的十种必备工具
·教你用VC6做QQ对对碰外挂程序
·Netmsg 局域网聊天程序
·Windows消息大全
·VC++下使用ADO编写数据库程序
·VC++学习笔记(四)
·非法探取密码的原理及其防范
·怎样在VC++中访问、修改注册表

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
VC++中以追加方式向文本文件写入数据

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

VC++中以追加方式向文本文件写入数据

 

在VB、Asp中向文本文件追加数据很容易,只要设定一个参数为ForAppending就行了。

Sub OpenTextFileTest

   Const ForReading = 1, ForWriting = 2, ForAppending = 8

   Dim fso, f

   Set fso = CreateObject("Scripting.FileSystemObject")

   Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)

   f.Write "Hello world!"

   f.Close

End Sub


在c语言中,追加数据也比较简单,好像设定a+参数就可以了。

 

今天,我要用MFC中的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;

 

 




相关文章

相关软件