C++ std::stringstream的默认“填充字符”是什么?
它是实现定义的还是标准建议流的默认填充字符 示例代码:C++ std::stringstream的默认“填充字符”是什么?,c++,stringstream,clang++,libc++,setw,C++,Stringstream,Clang++,Libc++,Setw,它是实现定义的还是标准建议流的默认填充字符 示例代码: #include <iostream> #include <iomanip> #include <sstream> int main () { std::stringstream stream; stream << std::setw( 10 ) << 25 << std::endl; std::cout << stream.st
#include <iostream>
#include <iomanip>
#include <sstream>
int main ()
{
std::stringstream stream;
stream << std::setw( 10 ) << 25 << std::endl;
std::cout << stream.str() << std::endl;
}
使用clang++--stdlib=libc++
$ clang++ --stdlib=libstdc++ test.cpp
$ ./a.out | hexdump
0000000 20 20 20 20 20 20 20 20 32 35 0a 0a
000000c
$
$ clang++ --stdlib=libc++ test.cpp
$ ./a.out | hexdump
0000000 ff ff ff ff ff ff ff ff 32 35 0a 0a
000000c
版本
$ 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
我可以用
std::setfill(“”)来修复它,但我很想知道它是否是clangg
错误。根据27.5.5.2[basic.ios.cons]第3段/表128,流s
的默认填充字符是s.wilded(“”)
。但是,s.wilded(“”)
所产生的字符取决于std::locale
ass.wilded(c)
是(27.5.5.3[basic.ios.members]第12段):
std::使用切面(s.getloc())。加宽(c)
顺便说一句,当您只向流写入数据时,应该使用std::ostringstream
。Fedora19上没有“libc++”。你的是什么?@rickhg12hs,我在mac上。不太清楚linux。谢谢。所以它看起来像是一个带有实现的bugs.gaveled(“”)
同时使用libstdc++
和libc++
返回0x20
,这不是流的填充字符所使用的libc++
。看起来已经有了一个。
std::use_facet<std::ctype<cT>>(s.getloc()).widen(c)