What is ios::in|ios::out?

回眸只為那壹抹淺笑 提交于 2019-12-03 05:38:35
  • ios::in allows input (read operations) from a stream.
  • ios::out allows output (write operations) to a stream.
  • | (bitwise OR operator) is used to combine the two ios flags,
    meaning that passing ios::in | ios::out to the constructor
    of std::fstream enables both input and output for the stream.

Important things to note:

  • std::ifstream automatically has the ios::in flag set.
  • std::ofstream automatically has the ios::out flag set.
  • std::fstream has neither ios::in or ios::out automatically
    set. That's why they're explicitly set in your example code.

ios::in and ios::out are openmode flags, and in your case combined with a binary or (|) operation. Thus the file is opened for reading and writing.

 memberData.open("member.txt", ios::in|ios::out);

ios::in is used when you want to read from a file

ios::out is used when you want to write to a file

ios::in|ios::out means ios::in or ios::out, that is whichever is required is used

Here's a useful link

http://www.cplusplus.com/doc/tutorial/files/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!