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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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:
Append at the end of the stream by “seek[ing] to end before each write”
Open and seek immediately at the end after opening
Perform operation in binary as opposed to text
Open in read mode
Open in write mode
Truncate the stream on opening.
These values are just flags, so you can open a stream in read/write binary at the end with :
Concerning the way of using those values, it is as you wish. They are declared as public static fields in
std::ios_baseclass (see 27.4.2) thus it is possible to access them usingstd::ios::ateor even something likecout.binary!The points where you must take attention is that
std::ios_base::atedoes NOT implystd::ios_base::appnor doesstd::ios_base::outimpliesstd::ios_base::trunc. Each field has a different meaning, and a different case of use, though most of them can’t be used alone 🙂