Is it possible to write a method that takes a stringstream and have it look something like this,
void method(string st
Make your wrapper over std::stringstream. In this new class you can define whatever operator <<
you need:
class SSB {
public:
operator std::stringstream& () { return ss; }
template
SSB& operator << (const T& v) { ss << v; return *this; }
template
SSB& operator << (const T* v) { ss << v; return *this; }
SSB& operator << (std::ostream& (*v)(std::ostream&)) { ss << v; return *this; }
// Be aware - I am not sure I cover all <<'s
private:
std::stringstream ss;
};
void print(std::stringstream& ss)
{
std::cout << ss.str() << std::endl;
}
int main() {
SSB ssb;
print (ssb << "Hello" << " world in " << 2012 << std::endl);
print (SSB() << "Hello" << " world in " << 2012 << std::endl);
}