0
,我有下面的代碼的問題:SOCKET沒有指定類型
#pragma once
#include "includes.h"
#include "buffer.h"
class CSocket
{
bool udp;
int format;
char formatstr[30];
static sockaddr SenderAddr;
int receivetext(char*buf, int max);
public:
SOCKET sockid;
CSocket(SOCKET sock);
CSocket();
~CSocket();
bool tcpconnect(char*address, int port, int mode);
bool tcplisten(int port, int max, int mode);
CSocket* tcpaccept(int mode);
char* tcpip();
void setnagle(bool enabled);
bool tcpconnected();
int setsync(int mode);
bool udpconnect(int port, int mode);
int sendmessage(char*ip, int port, CBuffer* source);
int receivemessage(int len, CBuffer*destination);
int peekmessage(int size, CBuffer*destination);
int lasterror();
static char* GetIp(char*address);
static int SockExit(void);
static int SockStart(void);
static char* lastinIP(void);
static unsigned short lastinPort(void);
static char* myhost();
int SetFormat(int mode, char* sep);
};
我使用的代碼::塊。我收到以下錯誤,在編譯時間:
/home/nick/Desktop/39dylibsource/Base Code/39dll/socket.h|15|error: ‘SOCKET’ does not name a type|
/home/nick/Desktop/39dylibsource/Base Code/39dll/socket.h|16|error: expected ‘)’ before ‘sock’|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|16|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|25|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|34|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|43|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|50|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|59|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|66|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|74|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|85|error: expected constructor, destructor, or type conversion before ‘(’ token|
||=== Build finished: 11 errors, 0 warnings ===|
我已經包含在參考INCLUDES.H如下:
#include <sys/socket.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
我失去了一個指令或庫? SOCKET拼寫有所不同嗎?任何照明都會很棒!
代碼最初可能是用於使用SOCKET而不是int的Windows。 – 2012-07-07 03:59:26
真棒謝謝!出於好奇,#include和#include「something.h」有什麼區別(除了明顯的引號和括號的區別嗎?它的輸入是不同的,還是隻是兩種表達同一個東西的方式? –
nterry
2012-07-07 04:35:19
@ nterry:使用引號,編譯器搜索當前目錄,然後搜索系統目錄,使用尖括號只搜索系統目錄。免責聲明:標準並不要求完全相同;這只是它在實踐中的正常工作方式。找到一個匹配的文件,這兩者之間沒有區別。 – 2012-07-07 05:13:08