什么是ios :: in | ios :: out? [英] What is ios::in|ios::out?

查看:2961
本文介绍了什么是ios :: in | ios :: out?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读一些项目代码,发现了这一点,在这里MembersOfLibrary()是MenberOfLibrary类的构造函数

I was reading some project code and I found this,here MembersOfLibrary() is a constructor of class MenberOfLibrary

    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();
}

我无法理解-> ios :: in | ios :: out<- 请帮忙! 谢谢

I m not able to understand the meaning of --> ios::in|ios::out <-- Please Help out ! Thank You

推荐答案

  • ios::in允许从流中输入(读取操作).
  • ios::out允许向流输出(写操作).
  • |(按位或运算符)用于组合两个ios标志,
    意味着将ios::in | ios::out传递给构造函数
    std::fstream启用流的两者输入和输出.
    • 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.
    • 要注意的重要事项:

      • std::ifstream自动设置了ios::in标志.
      • std::ofstream自动设置了ios::out标志.
      • std::fstream自动没有ios::inios::out 放.这就是为什么要在示例代码中明确设置它们的原因.
      • 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 | ios :: out?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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