Regarding the compiler error:
I can reproduce the linking error on Linux, with g++ and Clang++, so it's not a specific Windows problem (I'm also using Boost 1.55.0, so it's not specific to 1.50).
I suppose it is caused by a template definition that is allowed in the header file, but not implemented in the source/library.
Solution (for the linking problem only): Instead of
input->open(file_path, std::ios_base::in);
use
input->open(file_path.string(), std::ios_base::in);
This circumvents the potentially misdefined template by using a string-based constructor.
Regarding the assertion error:
The issue is you need to initialize the file_descriptor_sink
separately, else the iostream initialization won't be handled properly. Use this code:
//We need to initialize the sink separately
boost::iostreams::file_descriptor_sink output2Sink(file_path, std::ios_base::out | std::ios_base::app);
MyNamespace::ofstream output2(output2Sink);
if ( output2.is_open() == false ) std::cout << "Unable to open @" << __LINE__ << std::endl;
output2 << "blah test test blah" << std::endl;
open()
doesn't seem to reset
the optional
that causes the assertion.
The same method needs to be applied to the the MyNamespace::ifstream
:
boost::iostreams::file_descriptor_source inputSource(file_path, std::ios_base::in);
MyNamespace::ifstream input(inputSource);
//Test reading back what we wrote earlier
std::string inputContent;
input >> inputContent;
//Prints: blah (only the first word is read!)
std::cout << "Read from test.txt: " << inputContent << std::endl;
Also note that it is not neccessary to apply the solution to avoid the compiler error from above.
With these modifications your program appears to be working on my system.