Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 获取本地主机名和 IP 地址的 C++ Windows 函数调用
我试过很多。如何在 C++ 中获取主机名。我正在使用 Windows 7。请任何人帮助我。
我用
#include“unistd.h”
#include<stdio.h> #include<Winsock2.h> #pragma comment(lib, "Ws2_32.lib") int main() { char szPath[128] = ""; WSADATA wsaData; WSAStartup(MAKEWORD(2, 2), &wsaData); gethostname(szPath, sizeof(szPath)); printf("%s", szPath); WSACleanup(); return 0; }