Oct 11, 2014 at 7:03am UTC
I'm trying to write the value of xcord to the file, but it's come out as jiberish like š™ for some reason.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
LPCSTR fPath = "C:\\c++ test.txt" ;
const float xcord = 5.3;
DWORD bytesToWrite;
HANDLE hFile = CreateFile(fPath,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL |FILE_ATTRIBUTE_ARCHIVE | SECURITY_IMPERSONATION,0);
if (hFile == 0)
{
cout << "hFile error " << endl;
}
WriteFile(hFile,&xcord,2,&bytesToWrite,0);
return 0;
}
Last edited on Oct 11, 2014 at 7:04am UTC
Oct 11, 2014 at 8:15am UTC
If you write the value as binary you have to read it as binary as well in order to make sense of it. Reading the binary representation of a float as text will give you gibberish, as you said.
Last edited on Oct 11, 2014 at 8:16am UTC