This looks suspect:
Code:
const char* array = stream.str().c_str();
You get a pointer from a temporary string object. This pointer is then invalidated once this temporary string object is destroyed. Is there any reason why you cannot write instead:
Code:
std::string array(stream.str())
?