Basically, in_avail for stringbufs is missing key bits.
#include <iostream> #include <sstream> #include <stdexcept> double test_stringstream() { double result; char* source = "1918"; std::stringstream s; s << source; std::string tmp = s.str(); std::streambuf* sb = s.rdbuf(); int i = sb->in_avail(); if (i) { s >> result; std::cerr << "conversion result = " << result << std::endl; } else { throw std::runtime_error("conversion failed"); } return result; } int main () { test_stringstream(); return 0; } I believe this to be a bug, and quite unintentional. However, it's pretty easily fixed. This is a tracker from RH bugzilla 159408 https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=159408 -- Summary: std::stringbuf vs. in_avail Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: libstdc++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: bkoz at gcc dot gnu dot org CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21955