Convert uint8 * to std :: string

Possible duplicate:
How to convert byte * to std :: string in C ++?

Hi guys,

I am on an embedded device and trying to get a message. This message is specified by the character const uint8* dataand its length.uint8 len

now i need std :: string to output my data.

+3
source share
3 answers

If you do not want to convert the encoding, this will work:

std::string s( data, data+len );

If you want to convert UTF-8 to any system encoding used by your platform, you need to use some tools for a specific platform.

+8
source

uint8* ? , :

std::string mystring(data);
+1

sizeof (uint8)!= sizeof (char) :

std::string output( len, 0 );
for ( size_t i = 0; i < len; ++i )
  output[ i ] = static_cast<char>( data[ i ] );
0
source

Source: https://habr.com/ru/post/1781649/


All Articles