#include <Windows.h>  
#include <winsock2.h>
这两个有重定义socket吗,怎么解决,老是提示重定义,求前辈指教。

解决方案 »

  1.   

    #include <Windows.h> 里面有#include <winsock2.h>
    试试不就知道了
      

  2.   

    看你要用WinSock 1.1还是2.0,使用时MSDN有说明如下:
    The Winsock2.h header file internally includes core elements from the Windows.h header file, so there is not usually an #include line for the Windows.h header file in Winsock applications. If an #include line is needed for the Windows.h header file, this should be preceded with the #define WIN32_LEAN_AND_MEAN macro. For historical reasons, the Windows.h header defaults to including the Winsock.h header file for Windows Sockets 1.1. The declarations in the Winsock.h header file will conflict with the declarations in the Winsock2.h header file required by Windows Sockets 2.0. The WIN32_LEAN_AND_MEAN macro prevents the Winsock.h from being included by the Windows.h header. An example illustrating this is shown below.
    具体参考:http://msdn.microsoft.com/en-us/library/windows/desktop/ms737629(v=vs.85).aspx
      

  3.   

    #define WIN32_LEAN_AND_MEAN就用socket1.1
      

  4.   

    直接包含#include <winsock2.h>,它里面已经包含了windows.h。这有一些socket例子,都是这样:
    http://download.csdn.net/detail/geoff08zhang/4571358