Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I ask an iostream if it is writeable?

Tags:

c++

iostream

In my code I am passed a reference to an iostream, that in this case is ultimately a file.
Is there any way to find out if, when it was opened, it was set to [in|out] not just [in]?

like image 636
Watchful Avatar asked Aug 16 '11 11:08

Watchful


1 Answers

After looking at all the members of IOS, iostream, ostream, i did not see any way to retrieve the openmode flag used. I guess you'll have to try to write something to your reference and catch any error it throws. Or depending on how it is set, check the result of bad().

like image 198
RedX Avatar answered Oct 20 '22 21:10

RedX