LANG/C++

[C++]10-4.cout, cin 그리고 endl의 정체

혀니리리 2023. 5. 18. 14:01
728x90
#include <iostream>
namespace mystd
{
	using namespace std;
    class ostream
    {
    public:
    	void operator<< (char * str)
        {
        	printf("%s", str);
        }
        void operator<< (char str)
        {
        	printf("%c", str);
        }
        void operator<< (int num)
        {
        	printf("%d", num);
        }
        void operator<< (double e)
        {
        	printf("%g", e);
        }
        void operator<< (ostream& (*fp)(ostream &ostm))
        {
        	fp(*this);
        }
    };
    ostream& endl(ostream &ostm)
    {
    	ostm << '\n';
        fflush(stdout);
        return ostm;
    }
    ostream cout;
}

int main(void)
{
	using mystd::cout;
    using mystd::endl;
    
    cout<<"Simple String";
    cout<<endl;
    cout<<3.14;
    cout<<endl;
    cout<<123;
    endl(cout);
}
728x90