Hello,
The code below works fine in 1_33, but throws a bad_alloc exception
after some 10-20K iterations in 1_34_0.
Am I doing something wrong? Did the API or usage requirements change?
Thanks,
Jeff
---------------------------------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include
#include
#include
#include
#include
#include
bool binaryFile2String(const std::string& filename, std::string& out)
{
std::ifstream is(filename.c_str(),
std::ios_base::in|std::ios_base::binary);
if ( is.bad() || is.fail() )
return false;
is.seekg(0,std::ios::end);
const std::ios::pos_type len(is.tellg());
if ( len > out.max_size() )
return false;
out.reserve(len);
is.seekg(0, std::ios::beg);
std::ostringstream os;
os << is.rdbuf();
if ( ! is && ! is.eof() )
return false;
out = os.str();
is.close();
return true;
}
int main(int argc, char** argv)
{
const char* inFileName = "/tmp/car.xml"; // put your data file here
int loops(20000);
if ( argc > 1 )
loops = atoi(argv[1]);
std::string stringData;
if ( ! binaryFile2String(inFileName,stringData) )
{
std::cerr<<"Failed reading file "< 0; --i)
{
if ( 0 == (i % 1000) )
std::cerr<<' '<