C++Win32APIReadFile()读取文件 |
|
www.nanhushi.com 佚名 不详 |
直接一起来看吧: #include <iostream.h> #include <Windows.h> #include <direct.h> #include <stdlib.h> #include <stdio.h> void main() { unsigned long lpNumber=0; char lpBuffer[50]="";//Examda提示:文件读取的内容 char IP_path[80]=""; getcwd(IP_path,80); strcat(IP_path,"\\IP.txt");//获得资源路径 HANDLE hFile= CreateFile(IP_path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 ); if(hFile==INVALID_HANDLE_VALUE) { MessageBox(NULL,"创建文件句柄出错","error",MB_OK); } int filesucc=ReadFile(hFile, lpBuffer, 50,//读取文件中多少内容 &lpNumber, NULL ); CloseHandle(hFile); if(filesucc==0) { MessageBox(NULL,"读取文件失败","error",MB_OK); } return; } http://ks.examda.com
|
|
|
文章录入:杜斌 责任编辑:杜斌 |
|
上一篇文章: C++/CLI的封送处理 下一篇文章: C++函数WSASocket() |
【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |
|
|