关于c++读写文件的小疑点

关于c++读写文件的小问题
用fstream file.open(txt, ios::in | ios::out);打开一个txt文件后 在进行写操作为什么不会覆盖全文本 而只是覆盖了与写入字符串相同的长度???
我是新手 求关爱关于c++读写文件的小疑点
------解决思路----------------------
规定如此。

如果你需要清空文件文件内容,你需要 iso::in 
------解决思路----------------------
 ios::out 
------解决思路----------------------
 ios::trunc
------解决思路----------------------
public member type 
<ios> <iostream> std::ios_base::openmodeType for stream opening mode flags
Bitmask type to represent stream opening mode flags.

A value of this type can be any valid combination of the following member constants: 

member constant opening mode 
app (append) Set the stream's position indicator to the end of the stream before each output operation. 
ate (at end) Set the stream's position indicator to the end of the stream on opening. 
binary (binary) Consider stream as binary rather than text.  
in (input) Allow input operations on the stream. 
out (output) Allow output operations on the stream. 
trunc (truncate) Any current content is discarded, assuming a length of zero on opening. 

These constants are defined in the ios_base class as public members. Therefore, they can be referred to either directly by their name as members of ios_base (like ios_base::in) or by using any of their inherited classes or instantiated objects, like for example ios::ate or cout.out.