VC驿站

 找回密码
 加入驿站

QQ登录

只需一步,快速开始

搜索
查看: 2610|回复: 2

VC++6.0

[复制链接]
22_avatar_middle
最佳答案
0 
在线会员 发表于 2022-4-19 11:51:17 | 显示全部楼层 |阅读模式
{
m_ListenSock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(m_ListenSock=INVALID_SOCKET)        {
        AfxMessageBox(_T("新建SOCKET失败!"));
        return;
}
UINT uPort=GetDlgItemInt(IDC_EDIT4);
if(uPort<=0 || uPort>65535){
AfxMessageBox(_T("请输入合适的端口:1-65535"));
goto __Error_End;
}
sockaddr_in service;
service.sin_family=AF_INET;
service.sin_addr.s_addr=INADDR_ANY;
service.sin_port=htons(uPort);


if(bind(m_ListenSock,(sockaddr*)&service,sizeof(sockaddr_in))==SOCKET_ERROR){
AfxMessageBox(_T("绑定端口失败!"));
goto __Error_End;
}
if(listen(m_ListenSock,5)==SOCKET_ERROR){
        AfxMessageBox(_T("监听失败!"));
goto __Error_End;
}
sockaddr_in clientAddr;
int iLen=sizeof(sockaddr_in);
SOCKET accSock=accept(m_ListenSock,(struct sockaddr*)&clientAddr,&iLen);
if(accSock=INVALID_SOCKET){
AfxMessageBox(_T("接受客户端失败!"));
goto __Error_End;
}
__Error_End:
closesocket(m_ListenSock);
}

聊天室Dlg.cpp
D:\bs\聊天室\聊天室Dlg.cpp(270) : error C2362: initialization of 'accSock' is skipped by 'goto __Error_End'
        D:\bs\聊天室\聊天室Dlg.cpp(265) : see declaration of 'accSock'
D:\bs\聊天室\聊天室Dlg.cpp(270) : error C2362: initialization of 'iLen' is skipped by 'goto __Error_End'
        D:\bs\聊天室\聊天室Dlg.cpp(264) : see declaration of 'iLen'
D:\bs\聊天室\聊天室Dlg.cpp(270) : error C2362: initialization of 'accSock' is skipped by 'goto __Error_End'
        D:\bs\聊天室\聊天室Dlg.cpp(265) : see declaration of 'accSock'
D:\bs\聊天室\聊天室Dlg.cpp(270) : error C2362: initialization of 'iLen' is skipped by 'goto __Error_End'
        D:\bs\聊天室\聊天室Dlg.cpp(264) : see declaration of 'iLen'
D:\bs\聊天室\聊天室Dlg.cpp(270) : error C2362: initialization of 'accSock' is skipped by 'goto __Error_End'
        D:\bs\聊天室\聊天室Dlg.cpp(265) : see declaration of 'accSock'
D:\bs\聊天室\聊天室Dlg.cpp(270) : error C2362: initialization of 'iLen' is skipped by 'goto __Error_End'
        D:\bs\聊天室\聊天室Dlg.cpp(264) : see declaration of 'iLen'
执行 cl.exe 时出错.
跟着视屏走的但还是报错。求解!!!




上一篇:求助,计算俩圆交点坐标
下一篇:ShellExecuteEx 函数如何返回TRUE与FALSE
85_avatar_middle
最佳答案
0 
online_vip 发表于 2022-4-19 15:28:31 | 显示全部楼层
VC 6.0不支持这种写法吧 把相关变量的声明写到最前面即可
89_avatar_middle
最佳答案
2 
在线会员 发表于 2022-4-20 20:36:25 | 显示全部楼层
你自己看看initialization of 'iLen' is skipped by 'goto __Error_End',这句话的意思是'iLen'的初始化被'goto __Error_End'跳过。你可以在开始的地方就声明iLen。不一定要等goto后才声明。
您需要登录后才可以回帖 登录 | 加入驿站 qq_login

本版积分规则

×【发帖 友情提示】
1、请回复有意义的内容,请勿恶意灌水;
2、纯数字、字母、表情等无意义的内容系统将自动删除;
3、若正常回复后帖子被自动删除,为系统误删的情况,请重新回复其他正常内容或等待管理员审核通过后会自动发布;
4、感谢您对VC驿站一如既往的支持,谢谢合作!

关闭

站长提醒上一条 /2 下一条

QQ|小黑屋|手机版|VC驿站 ( 辽ICP备09019393号-4 )|网站地图wx_jqr

GMT+8, 2023-12-3 18:09

Powered by CcTry.CoM

© 2009-2021 cctry.com

快速回复 返回顶部 返回列表