C++ cout operator

#ifndef CCOutPut_hpp

#define CCOutPut_hpp

#include <iostream>

class CCOutPut{

private:

    

public:

    CCOutPut(){

        

    }

    ~CCOutPut(){

        

    };

    

    CCOutPut& operator<<(int i){

        printf("%d",i);

        return *this;

    }

    

    CCOutPut& operator<<(short s){

        printf("%d",s);

        return *this;

    }

    

    CCOutPut& operator<<(char c){

        printf("%c",c);

        return *this;

    }

    

    CCOutPut& operator<<(const char* str){

        printf(str);

        return *this;

    }

    CCOutPut& operator<<(float f){

        printf("%f",f);

        return *this;

    }

    

    CCOutPut& operator<<(double dl){

        printf("%lf",dl);

        return *this;

    }

    

};

#define endl "\n"

#endif /* CCOutPut_hpp */

CCouPut.cpp

#include "CCOutPut.hpp"

#include "CCInPut.hpp"

CCOutPut out;

CCInPut in;

//int main(int argc,const char* agrv[]){

//    int nID = 1001;

//    float fMath = 95.5f;

//    char sName[20];

//    char sex = 'm';

//    in >> nID;

//    //in >> nID >> sName >> fMath >> sex;

//    out << "我的ID:" << nID << endl;

//    out << "我的成绩!" << fMath << endl;

//    out << "我的性别!" << sex << endl;

//    

//    return 0;

//}

猜你喜欢

转载自blog.csdn.net/pengkejie1314520/article/details/87881529