简体   繁体   English

ios::trunc 如何在 C++ 中为二进制文件工作?

[英]How does ios::trunc work in C++ for binary files?

When I write fout.open("file.dat",ios::out|ios::trunc|ios::binary);当我写fout.open("file.dat",ios::out|ios::trunc|ios::binary); does the file loose all its data at that instance or it will wait for something to be written and then data will be lost?该文件是否会在该实例中丢失所有数据,或者它会等待写入某些内容然后数据将丢失? (I hope you get my point, all I'm asking is whether just writting the above statement, ie fout.write() will invoke removal of records from a binary file or we need to pass some data to the file and then the previous data already stored in the file would be lost) (我希望你明白我的意思,我所要问的只是写上面的语句,即fout.write()是否会调用从二进制文件中删除记录,或者我们需要将一些数据传递给文件,然后是前一个已经存储在文件中的数据将丢失)

trunc 标志将在 open() 处将文件清零。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM