Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
335 views
in Technique[技术] by (71.8m points)

c++ - What's the difference between opening a file with ios::binary or ios::out or both?

I'm trying to figure out the difference between opening a file like:

fstream *fileName*("FILE.dat",ios::binary);

or

fstream *fileName*("FILE.dat",ios::out);

or

fstream *fileName*("FILE.dat",ios::binary | ios::out);

I found that all of these forms are identical: in all cases, the same output on the file is produced using either *fileName*<< or *fileName*.write().

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

ios::out opens the file for writing.

ios::binary makes sure the data is read or written without translating new line characters to and from on the fly. In other words, exactly what you give the stream is exactly what's written.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...