Mấy bác cho e hỏi chồng toán tử này mà trong class thì làm ntn vậy, e search mãi k ra
, toàn thấy dùng cho struct k thôi hà



#include <iostream>
using namespace std;
class cstring
{
private:
char *str;
public:
cstring();
cstring(char*);
~cstring();
friend istream& operator>>(istream& is, cstring &a);
friend ostream& operator<<(ostream& os, cstring a);
....
};
.....
istream& operator>>(istream& is, cstring &a)
{
is.getline(a.str, 1000);
return is;
}
ostream& operator<<(ostream& os, cstring a)
{
os<<a.str;
return os;
}
.....
#include <iostream>
using namespace std;
class cstring
{
private:
char *str;
public:
cstring();
cstring(char*);
~cstring();
[COLOR="#FF0000"]friend[/COLOR] istream& operator>>(istream& is, cstring &a);
[COLOR="#FF0000"]friend[/COLOR] ostream& operator<<(ostream& os, cstring a);
....
};
.....
istream& operator>>(istream& is, cstring &a)
{
is.getline(a.str, 1000);
return is;
}
ostream& operator<<(ostream& os, cstring a)
{
os<<a.str;
return os;
}
.....
#include <iostream>
using namespace std;
class cstring
{
private:
char *str;
public:
cstring();
cstring(char*);
~cstring();
friend istream& operator>>(istream& is, cstring &a);
friend ostream& operator<<(ostream& os, cstring &a);
....
};
.....
istream& operator>>(istream& is, cstring &a)
{
is.getline(a.str, 1000);
return is;
}
ostream& operator<<(ostream& os, cstring &a)
{
os<<a.str;
return os;
}
.....
Comment