Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use different ifstream modes in c++?

  1. According to the reference, if I use ifstream infile ( "test.txt" , ifstream::in ); it will Allow input operations on the stream. But what are some of the examples of the "input operations"?
  2. Is ifstream infile ( "test.txt" , ifstream::in | ifstream::binary ); the right syntax to use multiple flags?
  3. Will it make a difference if I change ifstream:: to iso:: ?

Thank you

like image 815
derrdji Avatar asked Dec 30 '25 15:12

derrdji


1 Answers

  1. According to the reference, if I use ifstream infile ( "test.txt" , ifstream::in ); it will Allow input operations on the stream. But what are some of the examples of the "input operations"?

Reading from a file which would mean everything an input stream can support. See istream member functions. Typically, you can do both formatted (using >>) and unformatted reads (using read). Remember that ifstream is a specialization of the basic_ifstream template for char type. Depending on your needs, say to read UTF-16 encoded file, you may have to use a different specialization (wifstream) or even use a special locale (read this to know more about locales).

  1. Is ifstream infile ( "test.txt" , ifstream::in | ifstream::binary ); the right syntax to use multiple flags?

Yes.

  1. Will it make a difference if I change ifstream:: to iso:: ?

No.

like image 144
dirkgently Avatar answered Jan 01 '26 05:01

dirkgently



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!