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

原文地址:https://www.cnblogs.com/qiengo/p/2609802.html