主题:为什么会有这样的错误提示?
程序如下:
#include <windows.h>
#include <stdio.h>
#define BUF_SIZE 256
int main(int argc,LPTSTR argv[])
{
HANDLE hIn,hOut;
DWORD nIn,nOut;
CHAR Buffer[BUF_SIZE];
if(argc!=3)
{
printf("Usage:cp file1 file2\n");
return 1;
}
hIn=CreateFile(argv[1],GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
if(nIn == INVALID_HANDLE_VALUE)
{
printf("Can not open input file.Error:%x\n",GetLastError());
return 2;
}
hOut=CreateFile(argv[2],GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(hOut == INVALID_HANDLE_VALUE)
{
printf("Can not open output file:Error:%x\n",GetLastError());
return 3;
}
while(ReadFile(hIn,Buffer,BUF_SIZE,&nIn,NULL)&&nIn>0)
{
WriteFile(hOut,Buffer,nIn,&nOut,NULL);
if(nIn!=nOut)
{
printf("Fatal write.Error:%x\n",GetLastError());
return 4;
}
}
CloseHandle(hIn);
CloseHandle(hOut);
return 0;
}
我是用borland c++ compiler 5.5.1编译的
可是出现了这样的错误提示:
---------- Borland C++ Compiler ----------
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
D:\bcc\Pro\test.cpp:
Warning W8012 D:\bcc\Pro\test.cpp 15: Comparing signed and unsigned values in function main(int,char * *)
Error E2034 D:\bcc\Pro\test.cpp 15: Cannot convert 'unsigned long' to 'void *' in function main(int,char * *)
*** 1 errors in Compile ***
Output completed (1 sec consumed) - Normal Termination
其中说的第15行就是:
if(nIn == INVALID_HANDLE_VALUE)
这样话那第21行if(nOut == INVALID_HANDLE_VALUE)也是同样的问题了哦
为什么会这样?
有没有方法?
这个程序在Visual C++下编译没有问题
#include <windows.h>
#include <stdio.h>
#define BUF_SIZE 256
int main(int argc,LPTSTR argv[])
{
HANDLE hIn,hOut;
DWORD nIn,nOut;
CHAR Buffer[BUF_SIZE];
if(argc!=3)
{
printf("Usage:cp file1 file2\n");
return 1;
}
hIn=CreateFile(argv[1],GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
if(nIn == INVALID_HANDLE_VALUE)
{
printf("Can not open input file.Error:%x\n",GetLastError());
return 2;
}
hOut=CreateFile(argv[2],GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(hOut == INVALID_HANDLE_VALUE)
{
printf("Can not open output file:Error:%x\n",GetLastError());
return 3;
}
while(ReadFile(hIn,Buffer,BUF_SIZE,&nIn,NULL)&&nIn>0)
{
WriteFile(hOut,Buffer,nIn,&nOut,NULL);
if(nIn!=nOut)
{
printf("Fatal write.Error:%x\n",GetLastError());
return 4;
}
}
CloseHandle(hIn);
CloseHandle(hOut);
return 0;
}
我是用borland c++ compiler 5.5.1编译的
可是出现了这样的错误提示:
---------- Borland C++ Compiler ----------
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
D:\bcc\Pro\test.cpp:
Warning W8012 D:\bcc\Pro\test.cpp 15: Comparing signed and unsigned values in function main(int,char * *)
Error E2034 D:\bcc\Pro\test.cpp 15: Cannot convert 'unsigned long' to 'void *' in function main(int,char * *)
*** 1 errors in Compile ***
Output completed (1 sec consumed) - Normal Termination
其中说的第15行就是:
if(nIn == INVALID_HANDLE_VALUE)
这样话那第21行if(nOut == INVALID_HANDLE_VALUE)也是同样的问题了哦
为什么会这样?
有没有方法?
这个程序在Visual C++下编译没有问题