Assigning unsigned char* buffer to a string

Posted by CPPChase on Stack Overflow See other posts from Stack Overflow or by CPPChase
Published on 2012-10-15T21:22:01Z Indexed on 2012/10/15 21:37 UTC
Read the original article Hit count: 190

Filed under:
|
|
|
|

This question might be asked before but I couldn't find exactly what I need.

My problem is, I have a buffer loaded by data downloaded from a webservice. The buffer is in unsigned char* form in which there is no '\0' at the end. Then I have a poco xml parser needs a string.

I tried assigning it to string but now I realized it would cause problem such as leaking.

here is the code:

DOMParser::DOMParser(unsigned char* consatData, int consatDataSize,
    unsigned char* lagData, int lagDataSize) {

Poco::XML::DOMParser parser;
std::string consat;
consat.assign((const char*) consatData, consatDataSize);
pDoc = parser.parseString(consat);
ParseConsat();
}

Poco xml parser does have a ParseMemory which need a const char* and size of data but for some reason it just gives me segmentation fault.

So I think it's safer to turn it to string. Thanks in advance.

© Stack Overflow or respective owner

Related posts about c++

Related posts about string