Namespaces
Variants
Views
Actions

Talk:cpp/io/basic istream/seekg

From cppreference.com
< Talk:cpp‎ | io

[edit] seekg and eofbit

This page tells that seekg clears eofbit, but I spent a lot of time seeking for an error. Result is next: if the flag eofbit was set, seekg can't do anything (but failbit was 0) and after calling seekg I got -1 from tellg. The solution was to call clear() before seekg to clear eofbit manually. I'm using gcc version 4.6.1. I don't know what standard says about this situation, but maybe this page should be corrected. --217.67.65.115 16:41, 11 March 2012 (PDT)

The standard seems to say that eofbit should be cleared -- section 27.7.2.3. 72.14.228.1 18:08, 11 March 2012 (PDT)
Sorry to resurrect a discussion, but perhaps it should be mentioned that some compilers don't clear the eofbit with seekg right now? I also spent a while trying to find why my stream wasn't valid after calling seekg, before finding and using the same solution as above. I'm using MSVC 12. --Jaggedspire (talk) 08:41, 3 April 2015 (PDT)
Just saying that some particular compiler has a bug is going to be outdated (and not having a link to a bug report makes it hard to find out if it is outdated), If it's still an issue in the VS 2015 preview and there is a bug report, it may be helpful to link it in the Notes section (and if this wasn't reported, report it. gcc fixed this a while back). See for example std::atomic_compare_exchange_strong which mentions bug reports in three different compilers (although that example isn't best because bug reports are mentioned inline in an example, Notes is the better section). --Cubbi (talk) 11:41, 3 April 2015 (PDT)
It turns out I was mistaken regarding the setting of eofbit. It only seemed like I was experiencing issues with seekg failing to clear the eofbit: it does clear the eofbit, as it is supposed to. I wasn't taking into account the possibility of the getline setting the failbit, which naturally prevents getline from fetching the next line from the stream, regardless of position. Thank you for your input on the matter, as you clarified matters for me, and it was when I was attempting to put together an example for the bug report that I realized my mistake. --Jaggedspire (talk) 13:04, 3 April 2015 (PDT)