std :: ios_base :: ate和std :: ios_base :: trunc [英] std::ios_base::ate and std::ios_base::trunc

查看:1600
本文介绍了std :: ios_base :: ate和std :: ios_base :: trunc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

std :: ios_base :: ate 除std :: ios_base :: app ,例如)和 std :: ios_base :: trunc std :: ios_base :: out 例如)?



我应该优先写 std :: ios_base :: smth ,而不是 std :: ios :: smth

解决方案

std :: ios_base :: ate position光标在文本的末尾,而std :: ios_base_app在末尾附加文本(带有写操作),尽管你仍然可以从头开始读):



std :: ios_base :: trunc截断文件,因此它被清空,而std :: ios_base :: out只是指定要写入流。



不能引用标准(在我的平板电脑上,Acrobat Reader不会允许复制),但是从ISO 14882:1998的第27.4.2.1.4节,您可以在链接上看到的信息几乎是准确的:http://cplusplus.com/reference/iostream/ios_base/openmode/



总结:

  std :: ios_base :: app = append 

通过在每次写入之前seek [ing]结束,在流末尾添加

  std :: ios_base :: ate =结束时

打开并在打开后立即查找结束

  std :: ios_base :: binary = binary 



以文本形式执行二进制操作

  std :: ios_base :: in = input 

以读取模式打开

  std :: ios_base :: out = output 

以书写模式打开

  std :: ios_base :: trunc = truncate 

开启时截断讯息串。



标志,所以你可以在读/写二进制流在最后打开流:

  std :: ios_base :: in | std :: ios_base :: out | std :: ios_base :: ate | std :: ios_base :: binary 






使用这些值,它是你想要的。它们在 std :: ios_base 类中被声明为公共静态字段(见27.4.2),因此可以使用 std :: ios :: ate ,甚至是 cout.binary






你必须注意的一点是 std :: ios_base :: ate 不表示 std :: ios_base: :app ,也不会 std :: ios_base :: out 也不表示 std :: ios_base :: trunc 。每个字段有不同的含义,不同的使用情况,虽然大多数不能单独使用:)


What the point of the std::ios_base::ate (other than std::ios_base::app, for example) and std::ios_base::trunc (other than std::ios_base::out, for example)?

And should i preferly write std::ios_base::smth instead of std::ios::smth?

解决方案

std::ios_base::ate position the cursor at the end of the text whereas std::ios_base_app appends text (with a write operation) at the end, though you can still read from the beginning :)

std::ios_base::trunc truncates the file so it is emptied, whereas std::ios_base::out just specify you want to write to the stream.

I currently can't quote the standard (on my tablet and Acrobat Reader won't let met copy) but from paragraph 27.4.2.1.4 from ISO 14882:1998 the information you can see on the link is almost exact: http://cplusplus.com/reference/iostream/ios_base/openmode/

To sum up:

std::ios_base::app = append

Append at the end of the stream by "seek[ing] to end before each write"

std::ios_base::ate = At The End

Open and seek immediately at the end after opening

std::ios_base::binary = binary

Perform operation in binary as opposed to text

std::ios_base::in = input

Open in read mode

std::ios_base::out = output

Open in write mode

std::ios_base::trunc = truncate

Truncate the stream on opening.

These values are just flags, so you can open a stream in read/write binary at the end with :

std::ios_base::in | std::ios_base::out | std::ios_base::ate | std::ios_base::binary


Concerning the way of using those values, it is as you wish. They are declared as public static fields in std::ios_base class (see 27.4.2) thus it is possible to access them using std::ios::ate or even something like cout.binary !


The points where you must take attention is that std::ios_base::ate does NOT imply std::ios_base::app nor does std::ios_base::out implies std::ios_base::trunc. Each field has a different meaning, and a different case of use, though most of them can't be used alone :)

这篇关于std :: ios_base :: ate和std :: ios_base :: trunc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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