C++ 文件操作 打开文件 模式标志描述ios::app追加模式。所有写入都追加到文件末尾。ios::ate文件打开后定位到文件末尾。ios::in打开文件用于读取。ios::out打开文件用于写入。ios::trunc如果该文件已经存在,其内容将在打开文件之前被截断,即把文件长度设为 0。 可以把以上两种或两种以上的模式结合使用,用法如下: ofstream outfile; outfile.open("file.dat", ios::out | ios::trunc );