This is an example on how to use C++ devices for C FILE*.
#include <iostream>
#include <boost/iostreams/stream_buffer.hpp>
namespace bios = boost::iostreams;
int main(int argc,char *argv[]) {
if (argc != 2) {
cerr << "\nSyntax:\n\t" << argv[0] << " <file name>\n" << endl;
return EXIT_FAILURE;
}
FILE *fp(NULL);
fp = fopen(argv[1],"w");
bios::stream_buffer<mds_fu::cFile_Sink> sbuf;
ostream ofs(&sbuf);
sbuf.open(fsink);
ofs.exceptions(ios::failbit | ios::badbit);
double val = 45.6;
ofs.write(reinterpret_cast<char*>(&val),sizeof(double));
ofs.flush();
sbuf.close();
sbuf.open(fsink);
ofs << "This is a test string" << endl;
ofs.flush();
ofs.seekp(-5,ios::cur);
ofs << "word" << endl;
fclose(fp); fp = NULL;
sbuf.close();
fp = fopen(argv[1],"ab");
fsink.set_FILEp(fp);
sbuf.open(fsink);
ofs << "Mic" << endl;
ofs.flush();
ofs.seekp(-3,ios::end);
ofs << "Des" << std::endl;
fclose(fp); fp = NULL;
sbuf.close();
fp = fopen(argv[1],"rb");
bios::stream_buffer<mds_fu::cFile_Source> sbuf2;
sbuf2.open(fsource);
istream ifs(&sbuf2);
ifs.exceptions(ios::badbit | ios::failbit);
ifs.seekg(-4,ios::end);
string str;
ifs >> str;
cout << "Read string: " << str << endl;
ifs.seekg(0,ios::beg);
ifs.read(reinterpret_cast<char*>(&val),sizeof(double));
cout << "Value read: " << val << endl;
fclose(fp); fp = NULL;
return EXIT_SUCCESS;
}