我的菜单在运行我的 winsock 应用程序时显示第一件事,我希望能够在启动时选择一个端口,但是我在将 int 转换为 PCSTR 或任何其他类型的转换时遇到问题,因为我尝试了一些。
这是一些代码:
我的头文件:
char* DEFAULT_PORT = "10187";
我的 cpp 文件:
cout << "\n Input port: ";
cin >> UserDefinedPort;
if (UserDefinedPort > 1000){
char* p = p + UserDefinedPort;
DEFAULT_PORT = p;
} else {
// err...
}
我的袜子功能的开始:
int SocketAddrInfo(int iResult, addrinfo* MySocket, addrinfo** MySocketResult){
iResult = getaddrinfo(NULL, DEFAULT_PORT, MySocket, MySocketResult);
if (iResult != 0) {
printf("Get address info failed with error: %d\n", iResult);
WSACleanup();
std::cout << "Server closing in 5 ";
for (int i = 4; i > 0; i--){
Sleep(1 * 1000);
cout << i << " ";
}
cout << "Server closing now!" << endl;
return 1;
}
return iResult;
}
无论我尝试什么方法,它都会引发 read mem 错误或某种类型的 kernel.dll 错误。
任何帮助都会很棒,在此先感谢!