ofstream doesn't write buffer to file

前端 未结 5 1349
耶瑟儿~
耶瑟儿~ 2021-01-24 06:56

I\'m trying to write the contents of buf pointer to the file created by ofstream.

For some reason the file is empty, however the contents of buf is never empty... What

5条回答
  •  悲&欢浪女
    2021-01-24 07:21

    You need to flush the ofstream before closing it. Try ofstr.flush(); before ofstr.close(); I had this error some time ago when I thought that closing the stream automatically flushes it but, as it turned out, it doesn't.

提交回复
热议问题