YXTS122
YXTS122
采纳率100%
2016-03-07 07:27 阅读 1.8k

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

2

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • 已采纳
    John_ToStr John_ToDebug 2016-03-07 10: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 2016-03-07 07:38
    点赞 评论 复制链接分享
  • oyljerry oyljerry 2016-03-07 07:49
  • John_ToStr John_ToDebug 2016-03-07 10:39

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

    点赞 评论 复制链接分享

相关推荐