I want to extend the std::fstream class from the <fstream> header. I plan to add a couple functions like std::fsteam create(path), std::vector<std::string> read_lines(path), etc.
What Im asking is pretty simple. Instead of creating a whole new class, I want to be able to just simply add the methods in another file and then just make std::fstream objects and use those new methods.
I have two files. file_helper.hh where I will declare the methods, and file_helper.cc where I will define them and link them to my main.cc file.
So, what do I write within file_helper.hh to add these new methods to std::fstream if possible? Is it even possible?
The way to do that in C++ is to add your own free-standing functions with the functionality you want:
And then you just use them as you would any function: