I have fstream that seems to fall into phantom's failure state, although checking it (by converting to bool ) does not display error flags. Subsequent reads do not work, which is unexpected.
#include <fstream>
Pay attention to the following conclusion: only the first sample was "parsed", and therefore at the end of the second sample retains its original value of 100 :
[ root@localhost ~]
If I perform a tellg() or tellp() operation on it, the subsequent read completes successfully, so the loop is not premature, and the second pattern is also multiplied by 2 to create 200 :
[ root@localhost ~]
This only happens to me in the following environment:
- CentOS 6 x86_64, GCC 4.4.7
- CentOS 6 x86_64, GCC 4.8.2 (via devtoolset-2)
I get the expected behavior with or without tellg() / tellp() , on:
(Where the listed compiler supports both C ++ 03 and C ++ 11, I tried this under both and did not notice any difference.)
Does my program have UB? Or is it a libstdc ++ error that I need to work with?
Update: OK, so this is a known thing . But Ditmar does not say whether this is standard, or the libstdc ++ error. For me it looks like error 40732 , but it was RESOLVED / WONTFIX , so why does my program work as expected in Coliru and CentOS 7? Ideally, I would like to better understand what is going on before putting this solution in place.
source share