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

I read some project code and I found this, here MembersOfLibrary () is the constructor of the MenberOfLibrary class

class MembersOfLibrary { public: MembersOfLibrary(); ~MembersOfLibrary() {} void addMember(); void removeMember(); unsigned int searchMember(unsigned int MembershipNo); void searchMember(unsigned char * name); void displayMember(); private: Members libMembers; }; MembersOfLibrary::MembersOfLibrary() { fstream memberData; memberData.open("member.txt", ios::in|ios::out); if(!memberData) { cout<<"\nNot able to create a file. MAJOR OS ERROR!! \n"; } memberData.close(); } 

I can not understand the meaning → ios :: in | ios :: out <- Please help! Thank you.

+6
source share
3 answers
  • ios::in allows you to enter (read operations) from a stream.
  • ios::out allows you to output (write operations) to the stream.
  • | (bitwise OR operator) is used to combine two ios flags,
    which means ios::in | ios::out ios::in | ios::out to constructor
    from std::fstream allows you to input and output a stream.

It is important to note:

  • std::ifstream ios::in flag is automatically set.
  • std::ofstream ios::out flag is automatically set.
  • std::fstream has neither ios::in nor ios::out automatically set. This is why they are explicitly defined in your sample code.
+6
source

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

+3
source
  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 that ios :: in or ios :: out, i.e. depending on what is required, is used

Here is a useful link

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

+2
source

Source: https://habr.com/ru/post/982022/


All Articles