Q:

c++ save formatted dword to str variable

I'm new to C++ ,so forgive my ignorance. 
_tprintf(_T("%4.4X-%4.4X"), HIWORD(dwVolumeSerialNumber), LOWORD(dwVolumeSerialNumber))

this prints out for e.g : 48AE-2022  . 
i need to store it in a str var to write it to a text file.  I tried to_string(), but it stores the number 9 which i'm guessing is the number of characters. 

A:

TCHAR szBuff[100];
_stprintf_s(szBuff, sizeof(szBuff)/sizeof(TCHAR), _T("%4.4X-%4.4X"), HIWORD(dwVolumeSerialNumber), LOWORD(dwVolumeSerialNumber));

Or you also could do it C++ style:
#include <sstream>
#include <string>

std::stringstream ss;
ss<<std::hex<<std::setfill('0')<<std::setw(4)<<HIWORD(dwVolumeSerialNumber)<<"-"<<std::setw(4)<<LOWORD(dwVolumeSerialNumber));

std::string sRes = ss.str();

In that case you should use std::string or std::wstring depending on your project unicode settings.