Input/ Output with files Flashcards

1
Q

what is difference between ofstream, ifstream and fstream

A

ofstream: stream class to write on files
ifstream: stream class to read from files
fstream: stream class to both read and write from/to files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Mention some open file modes

A

ios:in - open for input operations
ios:out - open for output operations
ios:binary - open in binary mode
ios:ate -set the initial position at the end of the file.
ios:app - all output operations are performed at the end of the file.
ios:trunk - if the file for output operations, it clears the contents of the file before writing data to it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Mention some flags in I/O

A

bad()
fail()
eof()
good()
clear()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the function of the eof()

A

Returns true if a file open for reading has reached the end.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference bewteen bad() and fail()

A

bad() returns true if a reading or writing operation fails while fail() returns true in the same case as bad() but also in the case that a format error happens

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is the function of clear()

A

Can be used to reset the state flags

How well did you know this?
1
Not at all
2
3
4
5
Perfectly