P
Paulo da Silva
Hi.
I am writing a "string" class and I would like to be able to do things like
MyString s;
cin >> s;
cout << s;
How can I do this?
I think the way to go is something like this:
friend istream &operator >> (istream &is,MyString &st);
istream &operator >> (istream &is,MyString &st)
{ ...
is.get(st.buffer,st.allocLen-1);
st.len=is.gcount();
...
return is;
}
But how much do I have to alloc? Is there a way to read until the buffer
is full, then, if needed, expand the buffer and continue reading?
Thanks for any comments/help.
I am writing a "string" class and I would like to be able to do things like
MyString s;
cin >> s;
cout << s;
How can I do this?
I think the way to go is something like this:
friend istream &operator >> (istream &is,MyString &st);
istream &operator >> (istream &is,MyString &st)
{ ...
is.get(st.buffer,st.allocLen-1);
st.len=is.gcount();
...
return is;
}
But how much do I have to alloc? Is there a way to read until the buffer
is full, then, if needed, expand the buffer and continue reading?
Thanks for any comments/help.