problem mit sockets bzw. close
-
ich versuche mich gerade unter linux mit sockets.allerdings habe ich da so meine probs.g++ sagt viel, unter anderem auch dass er close nicht kennt, aber socket() kennt er:
In file included from /usr/include/c++/3.2.2/backward/iostream.h:31,
from main.cpp:4:
/usr/include/c++/3.2.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
main.cpp: In functionint main()': main.cpp:18:
close' undeclared (first use this function)
main.cpp:18: (Each undeclared identifier is reported only once for each function it appears in.)so hier der code den ich von netkomp kopiert habe ^^:
[cpp]
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <iostream.h>int main(void)
{
int sock;if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
cout << "Fehler beim Erstellen des Socket!\n" << endl;
return 1;
}close(sock);
return 0;
}
-
Hi,
ich glaub es leigt einfach daran, das du die alten C++ headers nutzt, mach mal aus:#include <iostream.h> #include<stdio.h>
dies:
#include<iostream> #include <cstdio> using namespace std;
Mfg
Viets
-
und close(2) ist in unistd.h definiert.
Btw. solltest du lernen Compiler Warnungen/Fehler zu lesen