2 yxts122 YXTS122 于 2016.03.07 15:27 提问

os.setf(initial);这句到底起什么作用?

os.setf(initial);不管我有没有注释掉这条语句,运行结果都一样,感觉这条语句好像是多余的。图片图片

4个回答

John_ToStr
John_ToStr   Rxr 2016.03.07 18:37
已采纳

// using ios_base::fmtflags
#include // std::cout, std::ios_base, std::ios,
// std::hex, std::showbase
int main () {

// using fmtflags as class member constants:
std::cout.setf (std::ios_base::hex , std::ios_base::basefield);
std::cout.setf (std::ios_base::showbase);
std::cout << 100 << '\n';

// using fmtflags as inherited class member constants:
std::cout.setf (std::ios::hex , std::ios::basefield);
std::cout.setf (std::ios::showbase);
std::cout << 100 << '\n';

// using fmtflags as object member constants:
std::cout.setf (std::cout.hex , std::cout.basefield);
std::cout.setf (std::cout.showbase);
std::cout << 100 << '\n';

// using fmtflags as a type:
std::ios_base::fmtflags ff;
ff = std::cout.flags();
ff &= ~std::cout.basefield; // unset basefield bits
ff |= std::cout.hex; // set hex
ff |= std::cout.showbase; // set showbase
std::cout.flags(ff);
std::cout << 100 << '\n';

// not using fmtflags, but using manipulators:
std::cout << std::hex << std::showbase << 100 << '\n';

return 0;
}

lx624909677
lx624909677   Ds   Rxr 2016.03.07 15:38
oyljerry
oyljerry   Ds   Rxr 2016.03.07 15:49
YXTS122
YXTS122 你这链接不存在。。。。。。。
接近 2 年之前 回复
John_ToStr
John_ToStr   Rxr 2016.03.07 18:39

c++库里面的东西,是一个标志类型的变量。有用的,仅仅是当前你用不到

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!