// Print to an output stream. This is a friend function,
// so it is not a member of StrLib.
// Overload << as a friend function
friend ostream &operator<<(ostream &, const StrLib &);
// Read from an input stream.
// Overload >> as a friend function here.
friend istream &operator>>(istream &, StrLib &);
// Print to an output stream. This is a friend function,
// so it is not a member of StrLib.
// Overload << as a friend function
ostream &operator<<(ostream &out, const StrLib &str)
{
int size = str.length();
for (int i = 0; i < size; i++)
out << str.cstr[i] << endl;
return out;
}
// Read from an input stream.
// Overload >> as a friend function here.
istream &operator>>(istream &input, StrLib &str)
{
for (int i = 0; i < str.length(); i++)
input >> str.cstr[i];
return input; // enables cin >> x >> y;
}// end function
I am having an issue with my code. We are overloading the ostream and istream operator. Pretty much we have a class called StrLib and we are creating objects that only has a private data member that is also a pointer named
char *cstr;
we are trying to output for ostream and whenever we compile we are receiving over 70 errors.
The pointer is pointing to a array of characters and we are to output the array of characters as a string. or something. Can anyone point in the right direction and help would be greatly appreciated! thank you!