Is it implementation defined or standards suggest a default fill character for streams?
Sample code:
#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 was able to fix it with std::setfill(' '), but am curious to know if it is a clang bug.
The default fill character for a stream
siss.widen(' ')according to 27.5.5.2 [basic.ios.cons] paragraph 3/Table 128. What character results froms.widen(' ')is, however, dependent on thestd::localeass.widen(c)is (27.5.5.3 [basic.ios.members] paragraph 12):BTW, you should use
std::ostringstreamwhen you are only writing to the stream and there is no use ofstd::endlever.