|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
用友元函数给 string成员输入值时出错
friend std::istream & operator>>(std::istream & is, const shcoo & y)
以下贴出源码
#include <iostream>
#include <string>
using std::string;
class shcoo
{
private:
string S_ne;
public:
shcoo(const string & x);
void xie();
void xian();
////????
friend std::istream & operator>>(std::istream & is, const shcoo & y)
{
is >> y.S_ne; //为什么执行到这里的时候出错???
return is;
}
/////????
friend std::ostream & operator<<(std::ostream & os, const shcoo & y);
};
/////--->>>
std::ostream & operator<<(std::ostream & os, const shcoo & y)
{
std::cout << y.S_ne << std::endl;
return os;
}
void shcoo::xian()
{
std::cout << S_ne << std::endl;
}
void shcoo::xie()
{
std::cin >> S_ne;
}
shcoo::shcoo(const string & x)
{
S_ne = x;
}
|
|