输入输出流,看似复杂却更好用----小话c++(2) (五)

2014-11-24 12:01:29 · 作者: · 浏览: 11
~__mask; 是将流状态中的_S_dec, _S_oct, _S_hex标志全部清除,然后加上特定的标志。而cout.setf(ios::hex);的方式仅仅是将十六进制标志加入流状态中,但是流状态中的十进制输出状态依然保留,导致依然按照十进制输出了。

了解了代码内部原理,外部不管发生了多么神奇的现象,都显得很单纯。


Q: 对于输入和输出流,clear和sync函数的区别是什么?
A: clear只表示流状态标志的清理。


[cpp] /**
* @brief [Re]sets the error state.
* @param state The new state flag(s) to set.
*
* See std::ios_base::iostate for the possible bit values. Most
* users will not need to pass an argument.
*/
void
clear(iostate __state = goodbit);
/**
* @brief [Re]sets the error state.
* @param state The new state flag(s) to set.
*
* See std::ios_base::iostate for the possible bit values. Most
* users will not need to pass an argument.
*/
void
clear(iostate __state = goodbit);
而对于sync函数或者flush函数才真正将缓冲区数据进行刷新。


xichen
2012-5-31 11:47:56

[cpp]

摘自 陈曦的分享