Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我 out.txt包含文本Hello World
out.txt
Hello World
如果我这样做
fstream ("out.txt" , ios::out)
然后,如果我尝试打开文件,它将为空。
我的问题是当我打开文件流到带有ios::out标志的文件时
ios::out
文件是空的。
但它是否进入文件并删除其所有内容
还是它创建了一个新的空文件并覆盖了旧文件?
我认为这取决于操作系统。
有些保留每个文件的版本化世代。在这种情况下,您可能每次都会得到一个新的。
它是同一个文件,其内容已被删除。为了附加到您必须使用的文件ios::app
ios::app
它应该截断文件,这意味着保持相同的文件条目,并且只清除内容。