Std :: istringstream >> double strange behavior

The following code prints 0 on mac osx with clang. In other places, it prints 5 ( clang , gcc )

#include <iostream> #include <sstream> int main() { std::istringstream iss("5C3"); double n; iss >> n; std::cout << n << std::endl; return 0; } 

 Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn) Target: x86_64-apple-darwin14.5.0 Thread model: posix 

When I use int , it prints 5 as expected.

How does the → operator from std :: istringstream work and why does this happen? Is there a way to make it work sequentially? (this is excerpt 5)

+5
source share
1 answer

Relevant part of the standard [istream.formatted.arithmetic] . The behavior of the extractor depends on the locale num_get<> object.

There is an error in double in the lib ++ num_get::do_get function described in this error report . On other platforms, you are probably using libstdc ++, which gives the expected behavior.

+3
source

All Articles