Can i output some text to a file using solely boost libraries?
The code i have (official documentation):
#include <ostream>
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/stream.hpp>
namespace io = boost::iostreams;
int main()
{
io::stream_buffer<io::file_sink> buf("log.txt");
std::ostream out(&buf);
// out writes to log.txt
out << "abc";
}
Is there another way? (i dont want to use std streams). Thanks in advance.
Input and output in a C++ program can be done in four ways:
<< and >>.FILE API: fopen, fprintf/fwrite/fgets/fread/etc. I think there are Boost I/O streams that handle FILE, but then you are still using the stream operators << and >>.Boost I/O streams isn't supposed to be a stand-alone API, instead it is using one of the above I/O systems to simplify some things for the programmer.
io::stream_buffer is derived from std::basic_streambuf, so you can use native basic_streambuf public methods, or you can use boost::filesystem streams, but all of such classes are derived from std:: classes.
http://www.boost.org/doc/libs/1_50_0/libs/filesystem/doc/reference.html#File-streams
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With