I have a GUID variable and I want to write inside a text file its value. GUID definition is:
typedef struct _GUID {          // size is 16
    DWORD Data1;
             
        
In case you prefer C++ way
std::ostream& operator<<(std::ostream& os, REFGUID guid){
    os << std::uppercase;
    os.width(8);
    os << std::hex << guid.Data1 << '-';
    os.width(4);
    os << std::hex << guid.Data2 << '-';
    os.width(4);
    os << std::hex << guid.Data3 << '-';
    os.width(2);
    os << std::hex
        << static_cast(guid.Data4[0])
        << static_cast(guid.Data4[1])
        << '-'
        << static_cast(guid.Data4[2])
        << static_cast(guid.Data4[3])
        << static_cast(guid.Data4[4])
        << static_cast(guid.Data4[5])
        << static_cast(guid.Data4[6])
        << static_cast(guid.Data4[7]);
    os << std::nouppercase;
    return os;
}
        
Usage:
static const GUID guid = 
{ 0xf54f83c5, 0x9724, 0x41ba, { 0xbb, 0xdb, 0x69, 0x26, 0xf7, 0xbd, 0x68, 0x13 } };
std::cout << guid << std::endl;
Output:
F54F83C5-9724-41BA-BBDB-6926F7BD6813