|
分類:[C/C++]
WriteFileで書き込んだ文字列が文字化けしてしまいます。 どうすればよろしいでしょうか?よろしくお願いします。
開発環境:visual studio 2019
const char TestData[NUMWRITES][TESTSTRLEN] = { "TestData0\n", "TestData1\n", "TestData2\n", "TestData3\n", "TestData4\n", "TestData5\n", "TestData6\n", "TestData7\n", "TestData8\n", "TestData9\n" };
int main(int argc, char* argv[]) { BOOL fSuccess = FALSE;
HANDLE hFile = CreateFile(TEXT("datafile.txt"), GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE) { printf("CreateFile failed (%d)\n", GetLastError()); return (1); } DWORD dwNumBytesWritten = 0;
for (int i = 0; i < NUMWRITES; i++) { fSuccess = WriteFile(hFile, TestData[i], TESTSTRLEN, &dwNumBytesWritten, NULL); // sync operation. if (!fSuccess) { printf("WriteFile failed (%d)\n", GetLastError()); return (2); } } }
|