+4  A: 

If you look at how all stream operators are declared they are of the form:

ostream& operator<<( const someType& val );

Essentially you want your overloaded function to actually do the output operation and then return the new updated stream operator. What I would suggest doing is the following, note that this is a global function, not a member of your class:

ostream& operator<< (ostream& out, const MyCustomString& str )
{
    return (out << str.data);
}

Note that if your 'data' object was private, which basic OOP says it probably should, you can declare the above operator internally as a 'friend' function. This will allow it to access the private data variable.

DeusAduro
Good point. Or he can use an accessor function.
Hooked
+1  A: 

That's not how you overload the << operator. You need to pass in a reference to an ostream and return one (so you can stack multiple <<, like std::cout << lol << lol2).

ostream& operator << (ostream& os, const MyCustomString& s);

Then just do this:

ostream& operator << (ostream& os, const MyCustomString& s)
{
   return os << s.data;
}
Hooked
+2  A: 

You need a free-standing function (friend of your class, if you make your data private as you probably should!)

inline std::ostream & operator<<(std::ostream &o, const MyCustomString&& d)
{
    return o << d.data;
}
Alex Martelli
+1  A: 

Firstly, you seem to have an issue with the definition of MyCustomString. It inherits privately from std::string as well as containing an instance of std::string itself. I'd remove one or the other.

Assuming you are implementing a new string class and you want to be able to output it using std::cout, you'll need a cast operator to return the string data which std::cout expects:

operator const char *()
{
    return this->data.c_str();
}
Jason Weathered