C++<<重载

阅读 45

2023-03-05

#include <iostream>



#include <string>



using namespace std;






class StringBad



{



private:


char *str;



public:


StringBad(char *value);


friend ostream &operator<<(ostream &os,const StringBad &st)


{


os<<st.str;


return os;


}



};



StringBad::StringBad(char *value)



{


str=value;



}



int main()



{


StringBad s("jianghuihong");


cout<<s<<endl;


return 0;



}

精彩评论(0)

0 0 举报