My class looks like:
class FileOut
{
private:
std::ofstream stream;
public:
FileOut(string sciezka);
~FileOut(void);
friend FileOut & operator<< (FileOut & obiekt, const char* w);
friend FileOut & operator<< (FileOut & obiekt, const string & w);
friend FileOut & operator<< (FileOut & obiekt, const char & znak);
friend FileOut & operator<< (FileOut & obiekt, const int & liczba);
friend FileOut & operator<< (FileOut & obiekt, const double & liczba);
friend FileOut & operator<< (FileOut & obiekt, std::endl);
//friend FileOut & endl (FileOut & obiekt);
};
operator<<
works fine for strings, char, int etc. (I put new characters to stream
).
I want to implement manipulator endl
for my class. Generally we override it this way:
ostream & endl (ostream & os){ return os << '\n'; }
but it won't work for my class. I declared
friend FileOut & endl (FileOut & obiekt);
but it doesn't work. How can I do it to be able to write:
FileOut save("file.txt");
save<<"tralalala"<<endl<<1123;
???