什么是ios :: in | ios :: out? [英] What is ios::in|ios::out?
本文介绍了什么是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 twoios
flags,
meaning that passingios::in | ios::out
to the constructor
ofstd::fstream
enables both input and output for the stream.-
std::ifstream
自动设置了ios::in
标志. -
std::ofstream
自动设置了ios::out
标志. -
std::fstream
自动没有ios::in
或ios::out
放.这就是为什么要在示例代码中明确设置它们的原因. std::ifstream
automatically has theios::in
flag set.std::ofstream
automatically has theios::out
flag set.std::fstream
has neitherios::in
orios::out
automatically
set. That's why they're explicitly set in your example code.
要注意的重要事项:
这篇关于什么是ios :: in | ios :: out?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文