以下语法的含义是:fstream myFile("test.txt",ios :: in | ios :: out | ios :: trunc); [英] What is the meaning of following syntax:: fstream myFile("test.txt", ios::in | ios::out | ios::trunc);

查看:141
本文介绍了以下语法的含义是:fstream myFile("test.txt",ios :: in | ios :: out | ios :: trunc);的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

fstream myFile("test.txt", ios::in | ios::out | ios::trunc);

编译器在C ++文件处理中如何解释这一行?

How is this line interpreted by the compiler in C++ file handling?

推荐答案

ios :: out 意味着您打算写入文件,而不是读取 ios :: in .在您的情况下,该流可以用于读取和写入.

ios::out means that you intend to write to the file in contrast to reading ios::in. In your case the stream can be used for both reading and writing.

ios :: trunc 表示将丢弃当前文件内容.将此与 ios :: app 进行比较,如果存在,您将在其中附加到文件.例如,如果未指定 ios :: in ,则暗示 ios :: trunc .当用于没有ios :: app的流时,ios :: ate或ios :: in,即表示ios :: trunc."

ios::trunc means that the current file content will be discarded. Compare this to ios::app where you will append to a file if it exists. ios::trunc is implied if not ios::in is specified for example. "When used for an ofstream without ios::app, ios::ate or ios::in, ios::trunc is implied."

奖金:

iso :: binary 意味着将要写的内容逐字放入文件中(否则,对于Windows \ n 可以用 \ n \代替r 例如)

iso::binary means that what you will write will be put verbatim into the file (otherwise for windows \n could be replaced with \n\r for example)

这篇关于以下语法的含义是:fstream myFile("test.txt",ios :: in | ios :: out | ios :: trunc);的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆