⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formatparams.cpp

📁 C++&datastructure书籍源码,以前外教提供现在与大家共享
💻 CPP
字号:
#include <iostream>
#include <iomanip>
using namespace std;

void output(ostream& out, ios_base::fmtflags flags)
// post: print using flags, restore old flags
{
    ios_base::fmtflags oldflags = out.flags(flags);

    out << "oldflags: " << oldflags << "\tnew: "
        << out.flags() << "\t";

    out << 12.47 << "\t" << true << "\t" 
        << 99.0  << "\t" << 255 << endl;

    out.flags(oldflags);  // restore as before
}

int main()
{
    output(cout, cout.flags());        // default
    output(cout, ios_base::showpos);   // leading +
    output(cout, ios_base::boolalpha); // print true
    output(cout, ios_base::showpoint); // show .0

    output(cout, ios_base::boolalpha|ios_base::hex);  // bool on, base 16
    output(cout, ios_base::hex|ios_base::showbase);   // show 0x in front
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -