以各种方式将茴字输入到某个文件
window API:
// c++_a.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <windows.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hFile;
DWORD nBytes;
//写入文件
hFile = CreateFile(_T("test.txt"), GENERIC_WRITE, FILE_SHARE_WRITE, NULL,CREATE_ALWAYS,0,NULL);
char msg[] = "茴香豆的茴";
if ( hFile != INVALID_HANDLE_VALUE)
{
WriteFile(hFile, msg, sizeof(msg) - 1, &nBytes, NULL);
CloseHandle(hFile);
}
//
hFile = CreateFile(_T("test.txt"), GENERIC_READ, FILE_SHARE_READ,NULL,OPEN_ALWAYS,0,NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
char line[256] = {0};
BOOL bResult;
bResult = ReadFile(hFile, line, sizeof(line), &nBytes,NULL);
if (nBytes != 0)
{
cout<<line<<endl;
}
CloseHandle(hFile);
}
system("pause");
return 0;
}