I've tried the following code with both normal ifstreams and the current boost:iostream I'm using, both have the same result.
It is intended to load a file from physfs into memory then pass it to a handler to process (eg Image, audio or data). Currently when c_str is called it only returns a small part of the file.
PhysFS::FileStream file("Resources/test.png" , PhysFS::OM_READ);
if(file.is_open()) {
String* theFile;
theFile = new String((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());
String::iterator it;
for ( it=theFile->begin() ; it < theFile->end(); it++ ) {
std::cout << *it;
} // Outputs the entire file
std::cout << theFile->c_str(); // Outputs only the first few lines
}
The iterator loop outputs the entire png file as expected, but the c_str call only returns the first few characters (\211PNG).
I've been trying variations of this code for quite some time with no success. Any ideas?