我在为字符串类重载 >> 运算符时遇到问题;这是我的课:
class str
{
char s[250];
public:
friend istream& operator >> (istream& is, str& a);
friend ostream& operator << (ostream& os, str& a);
friend str operator + (str a, str b);
str * operator = (str a);
friend int operator == (str a, str b);
friend int operator != (str a, str b);
friend int operator > (str a, str b);
friend int operator < (str a, str b);
friend int operator >= (str a, str b);
friend int operator <= (str a, str b);
};
这是重载的运算符:
istream& operator >> (istream& in, str& a)
{
in>>a.s;
return in;
}
问题是它只将字符串读取到第一个空格(句子中只有一个单词)。
我解决了。在 dreamincode 上找到了答案:D