I'm trying to write out a binary file. I have the data correctly inside a stringstream but the ofstream::write function wants a const char*.
[code=C++] std::stringstream str;
BinaryWriter writer(str); // From Poco library. str
writer << true
<< 'T'
<< 42
<< 3.14159265
<< "foo bar";
std::ofstream datFile;
datFile.open("test.dat", std::ofstream::binary);
datFile.write(reinterpret_cast<const char*>(str.str().c_str()), sizeof(str));
datFile.close();
[/code]
The datFile.write line works but it looks very ugly! Also, the sizeof(str) doesn't return the correct length.