Printing std::string over Serial with << operator

Hi, I have got following programming issue:

  1. I have a class called AFP (arbitrary fp)
  2. the AFP has got a method called toString(), which converts AFP type to std::string
  3. I want to print the AFP types via Serial
  4. Currently I am doing it this way ( c_str() converts std::string into char* ):
	AFP x;
string 	q = x.toString();
	Serial.print( q.c_str() );

the Serial.print( x.toString().c_str() ) does not work.

  1. Ideally I would be happy to do it as:

Serial << x << endl;

where Serial will be overloaded with something like (streaming.h lib):

template<class T> 
inline Print &operator <<(Print &stream, T arg) 
{ stream.print(arg); return stream; }

inline Print &operator <<(Print &obj, const AFP arg) 
{ obj.print(arg.toString().c_str() ); return obj; }

I’ve seen the “Streaming C+±style Output with Operator <<” library, but I would need an advice how to actually fit my scenario into the above Print template…

the Serial.print( x.toString().c_str() ) does not work.

What does this mean? It didn't compile? It printed "Happy Birthday, Monkey!" instead? It printed nothing? "It didn't work" is far too lame to deal with.