class item
{
string name;
string identifier;
public:
item( string name,string id):{this->name=name;this->identifier=id;}
friend ostream& operator<<(ostream&, const item&);
friend istream& operator>>(istream&, item&);
};
ostream& operator<<(ostream& out, const item& temp)
{
out<<item.name<<" "<<item.identifier<<endl;
return out;
}
istream& operator>>(istream& in, Cmessage& temp)
{
getline(in,item.name);//in case sring has space char
getline(in,item.identifier);
return in;
}
class CGuser
{
bool online;
int score;
string name;
string password;
string IP;
vector<item> messages;
vector<string> v_friends;
vector<string> groups;
public:
CGuser(string name, string password)
{
this->name=name;
this->password=password;
this->score=0;}
friend ostream& operator<<(ostream&, const CGuser&);
friend istream& operator>>(istream&, CGuser&);
ostream& operator<<(ostream& out, const CGuser& temp)
{
int size;
out<<temp.online<<endl;
out<<temp.score<<endl;
out<<temp.name<<endl;
out<<temp.password<<endl;
out<<temp.IP<<endl;
size=temp.messages.size();
out<<size<<" ";
for(int i=0;i<size;i++)
out<<temp.messages[i]<<endl;
size=temp.v_friends.size();
out<<size<<" ";
for(int i=0;i<size;i++)
out<<temp.v_friends[i]<<endl;
size=temp.groups.size();
out<<size<<" ";
for(int i=0;i<size;i++)
out<<temp.groups[i]<<endl;
out<<endl;
return out;
}
istream& operator>>(istream& in, CGuser& temp)
{
int size;
string stmp;
Cmessage cmg;
in>>temp.online;
in>>temp.score;
getline(in,temp.name);
getline(in,temp.password);
getline(in,temp.IP);
in>>size;
for(int i=0;i<size;i++)
{
in>>cmg;
temp.messages.push_back(cmg);
}
in>>size;
for(int i=0;i<size;i++)
{
getline(in,stmp);
temp.v_friends.push_back(stmp);
}
in>>size;
for(int i=0;i<size;i++)
{
getline(in,stmp);
temp.groups.push_back(stmp);
}
return in;
}
};
CGuser *user;
string name,pass;
cout<<"enter name:"<<endl
cin>>name;
cout<<"enter password"<<endl;
cin>>pass;
user= new CGuser(name,pass,0);
cout<<user;
the problem is with the last line, and what I mean problem is than it prints a number(I suspect the address in memory where user is allocated)instead of each field of the class
Another question that I have is how do I send over the network first just the item class, then the CGuser class(both client and server are the same endianess)