What is the default fill character for std :: stringstream?

Is this implementation specific or do standards offer a default fill character for threads?

Code example:

#include <iostream> #include <iomanip> #include <sstream> int main () { std::stringstream stream; stream << std::setw( 10 ) << 25 << std::endl; std::cout << stream.str() << std::endl; } 

With clang++ --stdlib=libstdc++

 $ clang++ --stdlib=libstdc++ test.cpp $ ./a.out | hexdump 0000000 20 20 20 20 20 20 20 20 32 35 0a 0a 000000c $ 

With clang++ --stdlib=libc++

 $ clang++ --stdlib=libc++ test.cpp $ ./a.out | hexdump 0000000 ff ff ff ff ff ff ff ff 32 35 0a 0a 000000c 

Version

 $ clang++ --version Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn) Target: x86_64-apple-darwin12.5.0 Thread model: posix 

I managed to fix it with std::setfill(' ') , but I'm curious to know if this is a clang error.

+7
c ++ clang ++ stringstream libc ++ setw
source share
1 answer

The default value for stream s is s.widen(' ') according to 27.5.5.2 [basic.ios.cons], clause 3 / Table 128. However, the characteristic features of s.widen(' ') depend on std::locale as s.widen(c) is (27.5.5.3 [basic.ios.members], clause 12):

 std::use_facet<std::ctype<cT>>(s.getloc()).widen(c) 

By the way, you should use std::ostringstream when you are only writing to the stream, and not use std::endl .

+6
source share

All Articles