I think I'm having a brain f*** at the moment. Why does this work:
Code:
#include <fstream>
#include <string>
int main()
{
char temp;
std::string str( "this is a string" );
std::ofstream out( "test.txt", ios::trunc );
temp = (char)str.size();
out.write( &temp, 1 );
out.close();
return 0;
};
...yet this doesn't:
Code:
#include <fstream>
#include <string>
int main()
{
std::string str( "this is a string" );
std::ofstream out( "test.txt", ios::trunc );
out.write( &((char)str.size()), 1 ); // ERROR HERE!!
out.close();
return 0;
};
The error I get is:
error C2102: '&' requires l-value
But shouldn't they be the same thing?