菜鸟求请教~这段程序编译老是出问题。。崩溃了
时间:2011-12-17
来源:互联网
#include "stdafx.h"
#include <iostream>
#include <string>
#include "winsock2.h"
#include "stdio.h"
using namespace std;
string getIp()
{
WSADATA wsaData;
WSAStartup(MAKEWORD(2,2),&wsaData); char HostName[128];
gethostname(HostName,128);
struct hostent* pHost = gethostbyname(HostName);
string ipstr = inet_ntoa(*(struct in_addr *)pHost-> h_addr_list[0]);
return ipstr;
WSACleanup();
}
int _tmain(int argc, _TCHAR* argv[])
{
cout << getIp() << endl;
system("pause");
return 0;
}
报错说
无法解析的外部符号
WSAStartup gethostname gethostbyname inet_ntoa WSACleanup
为什么不能用这些函数了? 已经#include "winsock2.h"了啊
#include <iostream>
#include <string>
#include "winsock2.h"
#include "stdio.h"
using namespace std;
string getIp()
{
WSADATA wsaData;
WSAStartup(MAKEWORD(2,2),&wsaData); char HostName[128];
gethostname(HostName,128);
struct hostent* pHost = gethostbyname(HostName);
string ipstr = inet_ntoa(*(struct in_addr *)pHost-> h_addr_list[0]);
return ipstr;
WSACleanup();
}
int _tmain(int argc, _TCHAR* argv[])
{
cout << getIp() << endl;
system("pause");
return 0;
}
报错说
无法解析的外部符号
WSAStartup gethostname gethostbyname inet_ntoa WSACleanup
为什么不能用这些函数了? 已经#include "winsock2.h"了啊
作者: ghetto 发布时间: 2011-12-17
引入库文件ws2_32.lib
作者: gold_water 发布时间: 2011-12-17
哈哈 搞定了 谢谢 太感谢了
作者: ghetto 发布时间: 2011-12-17
谢谢 就是这个问题!
引用 1 楼 gold_water 的回复:
引入库文件ws2_32.lib
引入库文件ws2_32.lib
作者: ghetto 发布时间: 2011-12-17
书上的例子?
作者: coolcoffee4051982 发布时间: 2011-12-17
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28