Data type to handle C++ and Boost streams?
Hi all, Bit of a basic question - I'd like to have some functions that work with files (using std::fstream) but can also handle boost::iostreams. Is there a data type I can use that can handle both? For example: void writeSomeData(std::fstream out); I can't pass a boost::iostream::stream to this function. What type can I use to achieve this? Many thanks, Adam.
[Please do not mail me a copy of your followup]
boost-users@lists.boost.org spake the secret code
Bit of a basic question - I'd like to have some functions that work with files (using std::fstream) but can also handle boost::iostreams. Is there a data type I can use that can handle both? For example:
void writeSomeData(std::fstream out);
I can't pass a boost::iostream::stream to this function. What type can I use to achieve this?
Use the common base of std::basic_istream, std::basic_ostream, std::basic_iostream. I describe doing this in order to be able to unit test file handling code with a string stream in this blog post: How Do I Unit Test Something That Writes To A File? http://wp.me/pyVNs-V -- "The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download http://legalizeadulthood.wordpress.com/the-direct3d-graphics-pipeline/ Legalize Adulthood! http://legalizeadulthood.wordpress.com
On Sat, Sep 12, 2009 at 6:59 PM, Adam Nielsen
Hi all,
Bit of a basic question - I'd like to have some functions that work with files (using std::fstream) but can also handle boost::iostreams. Is there a data type I can use that can handle both? For example:
void writeSomeData(std::fstream out);
I can't pass a boost::iostream::stream to this function. What type can I use to achieve this?
void writeSomeData(std::ostream &out); -- Cory Nelson http://int64.org
void writeSomeData(std::fstream out);
I can't pass a boost::iostream::stream to this function. What type can I use to achieve this?
void writeSomeData(std::ostream &out);
Ah, of course! Thanks guys, just what I needed (std::iostream in this case.) Interesting idea with the unit tests too Richard, I'll have to come back to that. Cheers, Adam.
participants (3)
-
Adam Nielsen
-
Cory Nelson
-
legalize+jeeves@mail.xmission.com