Last active
November 18, 2015 17:02
-
-
Save AbigailBuccaneer/86db884555cb821d60ad to your computer and use it in GitHub Desktop.
std::istream::ignore is inconsistent with regards to eof()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
#include <fstream> | |
using namespace std; | |
int main(int argc, char** argv) { | |
string s("ab"); | |
{ | |
istringstream stream(s); | |
stream.ignore(1); stream.ignore(1); | |
cout << stream.good() << endl; // 1 | |
} | |
{ | |
istringstream stream(s); | |
stream.ignore(2); | |
cout << stream.good() << endl; // 0 | |
} | |
{ | |
ifstream stream("test.cc"); | |
stream.seekg(0, ios_base::end); | |
size_t size = stream.tellg(); | |
stream.seekg(0, ios_base::beg); | |
for (size_t i = 0; i < size; ++i) { | |
stream.ignore(); | |
} | |
cout << stream.good() << endl; // 1 | |
} | |
{ | |
ifstream stream("test.cc"); | |
stream.seekg(0, ios_base::end); | |
size_t size = stream.tellg(); | |
stream.seekg(0, ios_base::beg); | |
stream.ignore(size); | |
cout << stream.good() << endl; // 0 | |
} | |
} |
Author
AbigailBuccaneer
commented
Nov 18, 2015
$ clang++ --version && clang++ test.cc && ./a.out
Ubuntu clang version 3.6.2-1 (tags/RELEASE_362/final) (based on LLVM 3.6.2)
Target: x86_64-pc-linux-gnu
Thread model: posix
1
0
1
0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment