I'm using this code to convert the unsigned char* (points to an array of 256 values) to std::string:
int ClassA::Func(unsigned char *dataToSend, int sendLength)
{
std::stringstream convertStream;
std::string dataToSendStr = "";
for(int i=0; i<=sendLength; i++) convertStream << dataToSend[i];
while(!convertStream.eof()) convertStream >> dataToSendStr;
...
}
but then I have dataToSendStr in this format:
dataToSendStr ""
[0] 0x00
[1] 0x00
[2] 0x04
[3] 0xC0
if I now use this value I only get "" and not the important values [0-3]!
-> need something like: dataToSendStr "000004C0"
Thx for your help!
for() ...construct to write the elements to a stream. You can usecopy( dataToSend, dataToSend+sendLength, ostream_iterator<string>(convertStream) );if you want to avoid hand-written loops.