现在我想将得来的数据写入本地文件当中,当程序执行一次,写入所得数据 。当在次运行程序,我想在第一次的基础上再往文件中添加数据。这个功能用哪个函数可以实现。提供相关例子者高分~~!!!
解决方案 »
- 请教有关网络流量基于snmp协议的,有关资料请说一下
- 更换MFC系统图标失真问题
- 关于结构链表的取值问题
- ATL 创建了DLL组件为什么不能使用?
- 关于异步通信与丢包的问题。
- 怎么样实现类似" word 中宏"的功能
- 请问在CRichEditCtrl中,可以不用SetSel、GetSelText实现指定位置字符的读取么?
- 怎么不能debug了???急!!!!!!!!!!!!!!
- 显卡是不是不占用内存?
- 怎么在启动属性表时把每个属性页激活一遍???
- 请问用InternetConnect(WINDOWS API)建立的FTP连接后,怎么判断这个连接是否断掉?
- 怎样根据外部函数是否存在决定是否调用该外部函数?
CFile就行了。
每次打开文件把指针移到文件末尾。
file.open("fd.txt",CFile::end|CFile::Write);
or ...file.seektoend();
file.write();
FILE *fp;
if((fp=fopen("c:\\abc.txt","a")))
{
fwrite("abcdefg",1,7,fp);
char enter[]={0x0d,0x0a,0};
fwrite(enter,1,2,fp);
fclose(fp);
}
2、
CFile file;
if(file.Open("c:\\abc.txt",CFile::modeReadWrite))
{
char enter[]={0x0d,0x0a,0};
file.SeekToEnd();
file.Write("hijklmn",7);
file.Write(enter,2);
file.Close();
}
* and "data2".It uses fclose to close "data" and
* _fcloseall to close all remaining files.
*/#include <stdio.h>FILE *stream, *stream2;void main( void )
{
int numclosed; /* Open for read (will fail if file "data" does not exist) */
if( (stream = fopen( "data", "r" )) == NULL )
printf( "The file 'data' was not opened\n" );
else
printf( "The file 'data' was opened\n" ); /* Open for write */
if( (stream2 = fopen( "data2", "w+" )) == NULL )
printf( "The file 'data2' was not opened\n" );
else
printf( "The file 'data2' was opened\n" ); /* Close stream */
if( fclose( stream ) )
printf( "The file 'data' was not closed\n" ); /* All other files are closed: */
numclosed = _fcloseall( );
printf( "Number of files closed by _fcloseall: %u\n", numclosed );
}
OutputThe file 'data' was opened
The file 'data2' was opened
Number of files closed by _fcloseall: 1