64,654
社区成员
发帖
与我相关
我的任务
分享
CFile中的open怎么用的啊···?
怎么打不开存在的文件??各位大大帮忙看看下面代码
void down_to_client(SOCKET sa)
{
int bytes;
char tem [259]="dir ";
long file_length;
int exist = 1;
char buf[4096];
char pathname[256];
memset(buf,0,sizeof(buf));
recv(sa,buf,BUF_SIZE,0);
memset(&pathname,0,sizeof(pathname));
strcpy(pathname,dir);
strcat(pathname,"\\");
strcat(pathname,buf);
CFile file;
exist=file.Open(pathname,CFile:: modeRead); //pathname="c:\\a.txt"时,返回值为0,c盘下有这个文件的,当执行完这步,a.txt变为空
//双击打开提示有程序在使用该文件···
if(!exist)
{
memset(buf,0,sizeof(buf));
DeleteFile(pathname);
ltoa(0, buf, 10);
send(sa,buf,BUF_SIZE,0);
return ;
}
file_length = file.GetLength();
memset(buf,0,sizeof(buf));
ltoa(file_length, buf, 10);
send(sa,buf,BUF_SIZE,0);
while(1)
{
bytes = file.Read(buf,BUF_SIZE);
if(bytes<=0)break;
send(sa,buf,bytes,0);
}
}
int main()
{
CFile file;
int exist = 1;
char pathname[256];
memset(&pathname,0,sizeof(pathname));
strcpy(pathname,"c:\\a.txt");
exist=file.Open(pathname,CFile:: modeRead);//返回值为1
cout<<exist<<endl;
}