I was tinkering with Boost Property Tree a bit, and I came across this example. I needed to convert the final result to vector, so I just added one more line after
write_json(ss, root);
like this:
std::vector<char> testVec(std::begin(ss.str()), std::end(ss.str()));
I have also tried this instead:
std::string someString = ss.str()
char* someArray = (char*)someString.c_str();
std::vector<char> someVec(someArray, someArray+sizeof(someArray));
In both the cases, I am getting this error:
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Any hints what I am doing wrong? It is not a problem of property tree, I gather. It is a problem of string to vector conversion. I guess this makes sense, because vectors are only supposed to be one dimensional, but I have no clue how to convert that string to vector and get it back again.