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

📄 main.cpp

📁 C++ Source code from a tutorial
💻 CPP
字号:
#include <iostream>
#include <stdlib.h>
#include <string>
#include <fstream>
#include <map>

using namespace std;

class MicrowaveOven {
    friend ostream &operator <<(ostream &out, 
        MicrowaveOven &oven);
public:
    typedef map<ostream *, bool> FlagMap;
    int HighVoltageRadiation;
    int RadioactiveFoodCount;
    int LeakLevel;
    string OvenName;
    static FlagMap Flags;
};

MicrowaveOven::FlagMap MicrowaveOven::Flags;

ostream &operator <<(ostream &out, MicrowaveOven &oven) {
    bool full = true;
    MicrowaveOven::FlagMap::iterator iter =
        MicrowaveOven::Flags.find(&out);
    if (iter != MicrowaveOven::Flags.end()) {
        full = iter->second;
    }
    if (full) {
        out << "High Voltage Radiation: ";
        out << oven.HighVoltageRadiation << endl;
        out << "Radioactive Food Count: ";
        out << oven.RadioactiveFoodCount << endl;
        out << "Leak Level: ";
        out << oven.LeakLevel << endl;
        out << "Oven Name: ";
        out << oven.OvenName;
    }
    else {
        out << oven.HighVoltageRadiation << ",";
        out << oven.RadioactiveFoodCount << ",";
        out << oven.LeakLevel << ",";
        out << oven.OvenName;
    }
    return out;
}

istream &operator >>(istream &in, MicrowaveOven &oven) {
    in >> oven.HighVoltageRadiation;
    in >> oven.RadioactiveFoodCount;
    in >> oven.LeakLevel;
    in >> oven.OvenName;
}

struct FullOvenManip {};
void FullOvenInfo(FullOvenManip x) {}
typedef void(*FullPtr)(FullOvenManip);
ostream &operator << (ostream &out, FullPtr) {
    MicrowaveOven::Flags[&out] = true;
    return out;
}

struct MinOvenManip {};
void MinOvenInfo(MinOvenManip x) {}
typedef void(*MinPtr)(MinOvenManip);
ostream &operator << (ostream &out, MinPtr) {
    MicrowaveOven::Flags[&out] = false;
    return out;
}

int main(int argc, char *argv[])
{
    MicrowaveOven myoven;
    myoven.HighVoltageRadiation = 9832;
    myoven.RadioactiveFoodCount = 7624;
    myoven.LeakLevel = 3793;
    myoven.OvenName = "Burnmaster";
    
    cout << myoven << endl;
    cout << "============" << endl;
    cout << FullOvenInfo << myoven << endl;
    cout << "============" << endl;
    cout << MinOvenInfo << myoven << endl;
    
    system("PAUSE");
    return 0;
}


⌨️ 快捷键说明

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