gpt4 book ai didi

c++ - Visual C++ 程序提示 net framework

转载 作者:行者123 更新时间:2023-11-28 07:42:14 24 4
gpt4 key购买 nike

我在 Visual C++ 2010 中编写了一个简单的客户端程序,它使用 winsock 连接到客户端。当我尝试在另一台计算机上运行该程序时,它会提示缺少 Net Framework。我想知道为什么会这样?我的代码中有什么需要网络框架?

错误信息:

application, you must first install one of the following versions of the .NET Framework v4.0...etc

这是我的代码

#pragma once
#pragma comment(lib, "Ws2_32.lib")

#include "stdafx.h"
#include <sdkddkver.h>
#include <WinSock2.h>
#include <Windows.h>
#include <iostream>
#include <string>
#include <time.h>
#include <cstring>
#include <sstream>

#define SCK_VERSION2 0x020

using namespace std;

void main() {
long Successful;
WSAData WinSockData;
WORD DLLVersion;
DLLVersion = MAKEWORD(2,1);
Successful = WSAStartup(DLLVersion, &WinSockData);
int sd,rcv,i,myint = 1;

hostent *host = gethostbyname("localhost");
char * myhostadd = inet_ntoa (*((struct in_addr *) host->h_addr_list[0]));

string memzi2,memzi,Converter;
char Message[200],tell[200] = "haa";

SOCKADDR_IN Address;

SOCKET sock;
sock = socket(AF_INET,SOCK_STREAM,NULL);

Address.sin_addr.s_addr = inet_addr(myhostadd);
Address.sin_family = AF_INET;
Address.sin_port = htons(7177);

cout << "Connecting to server...";
Successful = connect(sock, (SOCKADDR*)&Address, sizeof(Address));
u_long iMode=1;
ioctlsocket(sock,FIONBIO,&iMode);

if (Successful == 0) {
cout << "Connected. "<< endl;

for (;;++i) {
std::stringstream convert2;
convert2 << myint;
memzi2 = convert2.str();
std::cout << "Client: " << memzi2 << std::endl;
const char * c = memzi2.c_str();

sd = send(sock, c, sizeof(tell), NULL);
cout << "Server: ";
rcv = recv(sock,Message,sizeof(Message),NULL);
Converter = Message;
cout << Converter << endl;

std::stringstream convert1(Converter);
convert1 >> myint;
if (myint > 5000) {
myint = 1;
}
++myint;

}

closesocket(sock);

}
else cout << "Failed." << endl;

cout << "\n\n\t";
system("pause");
exit(1);
}

提前致谢!

最佳答案

可以是一个简单的原因,它将使用 C++ CLI,即公共(public)语言运行时。转到项目属性并修复它,它不会再显示。

关于c++ - Visual C++ 程序提示 net framework,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15569406/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com