mercredi 23 mai 2018

Creating a hex representative from a std::array

I have an std::array and I want to create a string from it by converting each byte to its equal HEX value something like this:

 string getString(array<unsigned char, 10> data)
 {
     // what is the faster way to do this?
 } 

main()
{
    array<unsigned char, 10> data={0,1,2,3,4,5,6,7,8,9};

   string result=getString(data);
   out<<result<<endl;
}

and it should print something such as:

0x00 0x01 0x02 0x03

or even

00010203040506070809

any way that is faster.

I know that I can use a for loop and do this job, but if there any neater way to do this?

Aucun commentaire:

Enregistrer un commentaire