了解了代码内部原理,外部不管发生了多么神奇的现象,都显得很单纯。
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]
摘自 陈曦的分享