现在我想将得来的数据写入本地文件当中,当程序执行一次,写入所得数据 。当在次运行程序,我想在第一次的基础上再往文件中添加数据。这个功能用哪个函数可以实现。提供相关例子者高分~~!!!

解决方案 »

  1.   

    很简单的呀,
    CFile就行了。
    每次打开文件把指针移到文件末尾。
      

  2.   

    CFile file;
    file.open("fd.txt",CFile::end|CFile::Write);
    or ...file.seektoend();
    file.write();
      

  3.   

    1、
    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();
    }
      

  4.   

    /* FOPEN.C: This program opens files named "data"
     * 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