What’s the difference between these two? Isn’t the in flag object thing redundant? Thanks.
std::ifstream file1("one.bin", std::ifstream::in | std::ifstream::binary);
std::ifstream file2("two.bin", std::ifstream::binary);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
From the docs on
ifstreamclass constructor:So when reading from a file, I would use
std::ifstream::inflag not because it’s required (or not) but because it would be a good programming practice to let a programming interface know what you are going to use it for.Edit:
The following is taken from http://www.cplusplus.com/doc/tutorial/files/, about
open()member function though (but the constructors in the code in the question probably callopen()copying the mode flags without modification).Nevertheless, many examples over the Web use
ifstream::inwhen showing a construction of anifstreamobject. Could really be some kind of a superstition practice, instead of a programming one.