#include <winsock2.h>
#include <stdio.h>
#include <windows.h>
#pragma comment(lib,"WS2_32.lib")
...
编译错误:
Compiling...
ClientDemo.cpp
D:\ClientDemo\ClientDemo.cpp(10) : warning C4003: not enough actual parameters for macro 'MAKEWORD'
D:\ClientDemo\ClientDemo.cpp(10) : error C2059: syntax error : ')'
执行 cl.exe 时出错.
为什么会编译错误?
7 个解决方案
#1
程序怎么写的?
#2
#include <winsock2.h>
#include <stdio.h>
#include <windows.h>
#pragma comment(lib,"WS2_32.lib")
int main(int argc,char* argv[])
{
WSADATA wsaData;
WORD sockVersion=MAKEWORD(2.0);
::WSAStartup(sockVersion,&wsaData);
SOCKET s=::socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(s==INVALID_SOCKET)
{
printf("Failed socket()\n");
::WSACleanup();
return 0; }
sockaddr_in servAddr;
servAddr.sin_family=AF_INET;
servAddr.sin_port=htons(80);
servAddr.sin_addr.S_un.S_addr=INADDR_ANY;
if(::connect(s,(sockaddr*)&servAddr,sizeof(servAddr))==-1)
{
printf("Failed connect()\n");
::WSACleanup();
return 0;
}
char buff[256];
int nRecv=::recv(s,buff,256,0);
if(nRecv>0)
{
buff[nRecv]='\0';
printf("接受到数据:%s",buff); }
::closesocket(s);
::WSACleanup();
return 0;
}
这个程序算是乱写的,实在惭愧啊,大家帮忙看看编译错误是什么意思吧
#include <stdio.h>
#include <windows.h>
#pragma comment(lib,"WS2_32.lib")
int main(int argc,char* argv[])
{
WSADATA wsaData;
WORD sockVersion=MAKEWORD(2.0);
::WSAStartup(sockVersion,&wsaData);
SOCKET s=::socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(s==INVALID_SOCKET)
{
printf("Failed socket()\n");
::WSACleanup();
return 0; }
sockaddr_in servAddr;
servAddr.sin_family=AF_INET;
servAddr.sin_port=htons(80);
servAddr.sin_addr.S_un.S_addr=INADDR_ANY;
if(::connect(s,(sockaddr*)&servAddr,sizeof(servAddr))==-1)
{
printf("Failed connect()\n");
::WSACleanup();
return 0;
}
char buff[256];
int nRecv=::recv(s,buff,256,0);
if(nRecv>0)
{
buff[nRecv]='\0';
printf("接受到数据:%s",buff); }
::closesocket(s);
::WSACleanup();
return 0;
}
这个程序算是乱写的,实在惭愧啊,大家帮忙看看编译错误是什么意思吧
#3
MAKEWORD(2,2),
#4
2 parameters
#5
改成MAKEWORD(2,2)也无法通过,汗的!!
#6
#include <winsock2.h>
#include <stdio.h>
#include <windows.h>
#pragma comment(lib,"WS2_32.lib")
int main(int argc,char* argv[])
{
WSADATA wsaData;
// WORD sockVersion = MAKEWORD(2.2);
WSAStartup(MAKEWORD(2,2), &wsaData);
SOCKET s=::socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(s==INVALID_SOCKET)
{
printf("Failed socket()\n");
::WSACleanup();
return 0; }
sockaddr_in servAddr;
servAddr.sin_family=AF_INET;
servAddr.sin_port=htons(80);
servAddr.sin_addr.S_un.S_addr=INADDR_ANY;
if(::connect(s,(sockaddr*)&servAddr,sizeof(servAddr))==-1)
{
printf("Failed connect()\n");
::WSACleanup();
return 0;
}
char buff[256];
int nRecv=::recv(s,buff,256,0);
if(nRecv>0)
{
buff[nRecv]='\0';
printf("接受到数据:%s",buff); }
::closesocket(s);
::WSACleanup();
return 0;
}
#7
这回我汗死了,原来我的代码那个逗号写成点了
谢了
谢了
#1
程序怎么写的?
#2
#include <winsock2.h>
#include <stdio.h>
#include <windows.h>
#pragma comment(lib,"WS2_32.lib")
int main(int argc,char* argv[])
{
WSADATA wsaData;
WORD sockVersion=MAKEWORD(2.0);
::WSAStartup(sockVersion,&wsaData);
SOCKET s=::socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(s==INVALID_SOCKET)
{
printf("Failed socket()\n");
::WSACleanup();
return 0; }
sockaddr_in servAddr;
servAddr.sin_family=AF_INET;
servAddr.sin_port=htons(80);
servAddr.sin_addr.S_un.S_addr=INADDR_ANY;
if(::connect(s,(sockaddr*)&servAddr,sizeof(servAddr))==-1)
{
printf("Failed connect()\n");
::WSACleanup();
return 0;
}
char buff[256];
int nRecv=::recv(s,buff,256,0);
if(nRecv>0)
{
buff[nRecv]='\0';
printf("接受到数据:%s",buff); }
::closesocket(s);
::WSACleanup();
return 0;
}
这个程序算是乱写的,实在惭愧啊,大家帮忙看看编译错误是什么意思吧
#include <stdio.h>
#include <windows.h>
#pragma comment(lib,"WS2_32.lib")
int main(int argc,char* argv[])
{
WSADATA wsaData;
WORD sockVersion=MAKEWORD(2.0);
::WSAStartup(sockVersion,&wsaData);
SOCKET s=::socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(s==INVALID_SOCKET)
{
printf("Failed socket()\n");
::WSACleanup();
return 0; }
sockaddr_in servAddr;
servAddr.sin_family=AF_INET;
servAddr.sin_port=htons(80);
servAddr.sin_addr.S_un.S_addr=INADDR_ANY;
if(::connect(s,(sockaddr*)&servAddr,sizeof(servAddr))==-1)
{
printf("Failed connect()\n");
::WSACleanup();
return 0;
}
char buff[256];
int nRecv=::recv(s,buff,256,0);
if(nRecv>0)
{
buff[nRecv]='\0';
printf("接受到数据:%s",buff); }
::closesocket(s);
::WSACleanup();
return 0;
}
这个程序算是乱写的,实在惭愧啊,大家帮忙看看编译错误是什么意思吧
#3
MAKEWORD(2,2),
#4
2 parameters
#5
改成MAKEWORD(2,2)也无法通过,汗的!!
#6
#include <winsock2.h>
#include <stdio.h>
#include <windows.h>
#pragma comment(lib,"WS2_32.lib")
int main(int argc,char* argv[])
{
WSADATA wsaData;
// WORD sockVersion = MAKEWORD(2.2);
WSAStartup(MAKEWORD(2,2), &wsaData);
SOCKET s=::socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(s==INVALID_SOCKET)
{
printf("Failed socket()\n");
::WSACleanup();
return 0; }
sockaddr_in servAddr;
servAddr.sin_family=AF_INET;
servAddr.sin_port=htons(80);
servAddr.sin_addr.S_un.S_addr=INADDR_ANY;
if(::connect(s,(sockaddr*)&servAddr,sizeof(servAddr))==-1)
{
printf("Failed connect()\n");
::WSACleanup();
return 0;
}
char buff[256];
int nRecv=::recv(s,buff,256,0);
if(nRecv>0)
{
buff[nRecv]='\0';
printf("接受到数据:%s",buff); }
::closesocket(s);
::WSACleanup();
return 0;
}
#7
这回我汗死了,原来我的代码那个逗号写成点了
谢了
谢了