You can write your own operator<<
like that:
std::ofstream& operator<<(std::ofstream& ofs, UINT16 d) {
ofs.write((char*)&d, sizeof(UINT16));
return ofs;
}
int main(int, char*[])
{
ofstream out("test", ios::out | ios::binary);
out << static_cast<UINT16>(16); // no variable declared
}
also with C++11 you could use user defined literals to make it even shorter:
inline UINT16 operator "" _u(unsigned long long value)
{
return static_cast<UINT16>(value);
}
and then:
out << 16_u;