-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06_WriteFile.cpp
More file actions
34 lines (28 loc) · 873 Bytes
/
Copy path06_WriteFile.cpp
File metadata and controls
34 lines (28 loc) · 873 Bytes
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
28
29
30
31
32
33
34
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
HANDLE hFile = CreateFile(L"D:\\hello\\demo.txt", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
cerr << "Create File Failed, Error No = " << GetLastError() << endl;
system("PAUSE");
return 1;
}
cout << "Create File Success" << endl;
system("PAUSE");
char chBuffer[] = "this is a demo file";
DWORD dwNoByteToWirte = strlen(chBuffer);
DWORD dwNoByteWritten = 0;
BOOL bFile = WriteFile(hFile, chBuffer, dwNoByteToWirte, &dwNoByteWritten, NULL);
if (bFile == FALSE)
{
cerr << "Error Writing data into file, Error No = " << GetLastError() << endl;
system("PAUSE");
return 1;
}
cerr << "Success Writing data into file" << endl;
system("PAUSE");
return 0;
}