C++ Note

1.write file

void outputFile(long time){
  char buf[128];
  int n=sprintf(buf,"%d",time);//write the content to buffer first!
  buf[n]=0;
  FILE *stream;
  stream= fopen( "./time.txt", "w+b" );
  fwrite(buf, 1,n, stream ); 
  fclose(stream);
}

  fwrite(buf, 1,n, stream );

  buf: the content to write

  1:the size of write per operation

  n:the size of content

posted @ 2012-07-26 12:17  Qiengo  阅读(136)  评论(0编辑  收藏  举报