#include <string> 但仍未找到标识符

#include <string> but identifier still not found

本文关键字:标识符 gt lt string #include      更新时间:2023-10-16

我正在尝试使用字符串来保存玩家名称。当我键入时

#include <string>

这是正确的工作,VS2010甚至自动填充文本。然后我尝试使用一个字符串,但我得到了一个找不到的标识符:

#include <string.h>
class Player{
    string name;
int playerIndex;
    int position;
public:
    Player(string name, int index, int pos);
    void move();
}; 

另一方面,相同的事情(或类似的事情正在发生在矢量)

#include <vector>
vector<cell> vBoard;

错误:Vector不是模板

C++库中的所有内容都在名称空间std中,这样就不会污染全局名称空间。您需要限定名称:

std::string name;
std::vector<cell> board;

您还使用了错误的标头名称;你想要<string>而不是<string.h>

您缺少名称空间

using namespace std;

或者尝试

std::string