C++ 31 Jan 2010 23:35:20
Snippet: Custom Type to Output Stream
//tinodidriksen.com/uploads/code/cpp/custom-to-ostream.cpp
#include <ostream> #include <iostream> #include <string> struct Custom { std::string m_str; friend std::ostream& operator<<(std::ostream& stm, const Custom& obj); }; std::ostream& operator<<(std::ostream& stm, const Custom& obj) { stm << obj.m_str; return stm; } int main() { Custom cst; cst.m_str = "waffles"; std::cout << cst << std::endl; }