#####################################################################################
VS2013中Run-Time Check Failure #2 - Stack around the variable 'xxx' was corrupted 错误
原因:数组越界
#define DATA_BUFIZE 64
getline(cin,str);
ZeroMemory(buf,BUFSIZ);
strcpy(buf,str.c_str());
Ret=send(sHost,buf,strlen(buf),0);
if(Ret==SOCKET_ERROR){
printf("send() is error\n");
closesocket(sHost);
WSACleanup();
return -1;
}
定义的DATA_BUFSIZE错写成BUFSIZE
#####################################################################################
vs2013 给 main 主函数传递字符串参数时只能获取首字符
原因:Unicode编码格式与多字符集的问题,工程默认是Unicode格式
解决方案:把Character Set选项设置为Use Multi-Byte Character Set
project->propertise->Configuration Propertise->General->Project Default->Character Set
两套字符集通用宏:
MultiByte | Unicode | 通用宏 | 功能 |
char | wchar_t | TCHAR | 字符 |
atoi | _wtoi | _ttoi | 字符串转换为int型 |
atof | _wtof | _tstof | 字符串转换为float型 |
_atoi64 | _wtoi64 | _ttoi64 | 字符串转换为64位整型 |
itoa | _itow | _itot | int 型转换为字符串 |
gcvt | _wtof | _tstof | float型转换为字符串 |
strlen | wcslen | _tcslen | 获取字符串长度 |
strstr | wcsstr | _tcsstr | 字符串截取 |
strcpy | wcscpy | _tcscpy | 字符串复制 |
_stprintf_s | sprintf_s | swprintf_s | 字符串赋值 |
#####################################################################################
vs2013代码结果是错的
原因:判断时少写了一个=号
Ret=recv(sClient,buf,BUFSIZE,0);
if(Ret=SOCKET_ERROR){
printf("recv() is error");
closesocket(sClient);
WSACleanup();
return -1;
}
#####################################################################################
VS2013中unresolved external symbol ##### referenced in function ########## 错误
原因:链接时找不到所涉及函数的定义或引用了外部库文件的函数时没有将依赖的库文件包含进来
例:
加入链接库ws2_32.lib
#pragma comment(lib,"ws2_32.lib")
#####################################################################################
VS2013中use ##函数 or ##函数 instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings 错误
原因:高版本vs在编译时默认使用新函数
新函数替换旧函数或者加入定义或者把SDL checks改为否(project->properties->Configuration Properties->c/c++->General->SDL checks)