[英]C++ Visual Studio class error identifier string is undefined
I made a class. 我上了课。 the header file is :
头文件是:
#pragma once
#include <string>
class Player
{
public:
Player();
private:
};
and the cpp file is : 和cpp文件是:
#include "Player.h"
#include <iostream>
Player::Player()
{
}
When I define a string in the header file and add an argument to the Player function in the header file everything works fine 当我在头文件中定义一个字符串并在头文件中向Player函数添加一个参数时,一切正常
#pragma once
#include <string>
class Player
{
public:
Player(string name);
private:
string _name;
};
but when I add the same argument to the Player function in the cpp file 但是当我在cpp文件中的Player函数中添加相同的参数时
#include "Player.h"
#include <iostream>
Player::Player(string name)
{
}
I get an error: identifier "string" is undefined and I get the same error in the header file as well so it effects that too. 我收到一个错误:标识符“字符串”未定义,我在头文件中也得到相同的错误,所以它也会产生影响。 I tried including string in the cpp file in hopes of solving the problem but it did not work.
我试图在cpp文件中包括字符串,以期解决问题,但是它没有用。 I'm really desperate for a solution, guys.
伙计们,我真的很想要一个解决方案。
All STL types, algorithms etc are declared inside std
namespace. 所有STL类型,算法等都在
std
命名空间内声明。
To make your code compile, string
type should also specify the namespace as: 要使代码编译,
string
类型还应将命名空间指定为:
Player(std::string name); /* Most recommended */
or 要么
using namespace std;
Player(string name); /* Least recommended, as it will pollute the available symbols */
or 要么
using std::string;
Player(string name);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.