I am using the following function to convert a byte array (Crypto++ key) to a Hex String
std::string Hexa::byte_to_hex_encoder(unsigned char *array, int len){
    std::stringstream ss;
    for(int i=0;i<len;++i)
        ss << std::hex << std::uppercase <<std::setw(2) <<(int)array[i];
    return ss.str();
}
The byte array is of size 16 and when I don't use setw(2) I get a hex string with lesser characters like 30 or sometimes 31. When I am using setw(2) I get random spaces in the hex string like
5CA0 138C5487D2C6D929EC36B694890
How can I convert a byte array to hex string and vice versa without spaces in the hex string?
 
                        
You also need
setfill('0')so that the numbers are properly padded.Without the
setw, a number like 7 comes out as just7, making your string short as you have seen. With thesetwbut nosetfill, it's padded to the right length, but with a space.Adding the
setfillensures it gets padded with zeroes.For your code that would be: