实现以下代码功能:
HANDLE hFile=CreateFile("aa.txt",GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile==INVALID_HANDLE_VALUE)
{
return FALSE;
}
DWORD dwSize=GetFileSize(hFile,NULL);
DWORD dwReaded;
CString strContent;
LPSTR lpszContent=strContent.GetBufferSetLength(dwSize);
if(!ReadFile(hFile,lpszContent,dwSize,&dwReaded,NULL) || dwReaded!=dwSize)
{
return FALSE;
}
CloseHandle(hFile);
要求:
必须一次性读完整个文件,不要一个字符一个字符、一个单词一个单词或是一行一行地读,不许有循环。以下代码不要:
ostringstream osContent;
ifstream inFile("aa.txt");
if(!inFile)
{
return -1;
}
char ch;
while(inFile.get(ch))
cout.put(ch); string strContent=osContent.str();达到有求立即给100分。
HANDLE hFile=CreateFile("aa.txt",GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile==INVALID_HANDLE_VALUE)
{
return FALSE;
}
DWORD dwSize=GetFileSize(hFile,NULL);
DWORD dwReaded;
CString strContent;
LPSTR lpszContent=strContent.GetBufferSetLength(dwSize);
if(!ReadFile(hFile,lpszContent,dwSize,&dwReaded,NULL) || dwReaded!=dwSize)
{
return FALSE;
}
CloseHandle(hFile);
要求:
必须一次性读完整个文件,不要一个字符一个字符、一个单词一个单词或是一行一行地读,不许有循环。以下代码不要:
ostringstream osContent;
ifstream inFile("aa.txt");
if(!inFile)
{
return -1;
}
char ch;
while(inFile.get(ch))
cout.put(ch); string strContent=osContent.str();达到有求立即给100分。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货