考虑以下代码:输入流的std :: setfill和std :: setw?
int xx;
std::cin >> std::setfill('0') >> std::setw(4) >> xx;
当发送12
标准输入我期待的xx
值是1200
和发送12345
时,我希望它是1234
。
但是,看起来std::setfill
和std::setw
没有效果,我分别得到12
和12345
。
这是一个错误还是根据标准?有没有一种很好的方法来获得预期的功能?
另请注意,当我将xx
的类型更改为std::string
时std::setw
生效,而std::setfill
仍然不生效。
我的编译器是gcc-7.0.1
。
也许我错过了。因为什么时候在* input *流操作上支持'std :: setfill'?我知道'std :: setw'是,但现在'std :: setfill'也是? – WhozCraig
不行,这是恶意代码。 –
我不认为输入流支持'std :: setfill'。 http://en.cppreference.com/w/cpp/io/manip/setfill – Shravan40