gpt4 book ai didi

c++ - Visual Studio 2012 Ultimate 无法识别字符串类型

转载 作者:行者123 更新时间:2023-11-28 06:09:00 34 4
gpt4 key购买 nike

<分区>

我正在尝试制作一个可以让我写信给某人的客户端-服务器程序。当我把它放在服务器端时,一切正常。现在我想在客户端实现我为服务器端所做的相同功能,Visual Studio 说我不能,因为他不识别“字符串”。我尝试了使用和不使用字符串的包含,但无论哪种方式都行不通。

这是客户端的代码:

#pragma once
//#include <winSock2.h>
//#include <Windows.h>
#include "ClientNetwork.h"
#include "NetworkData.h"
#include <string>
#include <string.h>

class ClientGame
{
public:
ClientGame();
~ClientGame(void);

ClientNetwork* network;

void sendActionPackets();

char network_data[MAX_PACKET_SIZE];

void update();

void sendMessagePacket(string message);
};

Visual Studio 给我“语法错误:标识符‘字符串’。然而,我清楚地以所有可能的方式将其包括在内。

此外,我在同一个项目中有相同的代码,但用于我程序的服务器端。在这里:

#pragma once
#include "ServerNetwork.h"
#include "NetworkData.h"

class ServerGame
{
public:
ServerGame(void);
~ServerGame(void);

void update();

void receiveFromClients();

void sendActionPackets();

void sendMessagePacket(string message);

private:

//IDs for the clients connection for table in ServerNetwork
static unsigned int client_id;

//The ServerNetwork object
ServerNetwork* network;

//data buffer
char network_data[MAX_PACKET_SIZE];
};

即使没有#include string/string.h,它也能正常工作。有人知道为什么这样做吗?

**编辑我应该指定,我也尝试过以这种方式将其限定为 std“std::string”。但是,它不会起作用。

**看起来已经“解决”了删除“string.h”包括但保留简单的“string”并添加“std::”范围解决了它。我仍然很困惑为什么我的服务器端版本没有问题。我不必包含它,也不必限定它的范围。无论如何,我应该没问题!谢谢! :)

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