C\C++对大文件的快速读写

#include
#include
#include
#include

using namespace std;

int   main() 

HANDLE       fh; 
HANDLE       MapFileH; 
HANDLE       OpenMap; 
HANDLE       MapHandle; 

fh=CreateFile("C:\cpp_1000000.txt ",  GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);       
    if(fh   ==   INVALID_HANDLE_VALUE)       
{       
cout<< "Error   in   CreateFile   ! " <
return       FALSE;       

MapFileH=CreateFileMapping( fh,NULL,PAGE_READWRITE,0,0,"Resource " ); 
if(MapFileH   ==   NULL) 
cout << "Error   in   CreateFileMapping! " <

OpenMap=OpenFileMapping(FILE_MAP_ALL_ACCESS,true, "Resource " ); 
if(OpenMap   ==   NULL) 
cout<< "Error   in   OpenFileMapping! " <

MapHandle=MapViewOfFile( OpenMap, FILE_MAP_ALL_ACCESS, 0, 0, 0 ); 
if(MapHandle   ==   NULL) 
cout   << "Error   in   MapViewOfFile! " <

//     对数据进行处理。 

UnmapViewOfFile(MapHandle); 
CloseHandle(OpenMap); 
CloseHandle(fh); 
return   0; 
}

你可能感兴趣的:(C\C++对大文件的快速读写)