I\'d like to overload << operator to write the value it takes to a file and cout. I have tried to do it with following code, but couldn\'t succeed it. It just writes t
It just writes the value to the text file because your operator<< method does not get called.
The operator<< should return a reference to the stream (ostream&) because otherwise << str << endl; would not work.
The other problem with your operator<< is that it could create an infinite loop since os << str; has the same signature than fl << "string";