【‘string‘ does not name a type / c++】

在 c++ 头文件中书写类声明的过程中:遇到

#ifndef CLIENT_H_   // 避免重复声明
#define CLIENT_H_   // 避免重复声明


class Dog{
private:
    string name;
    string weight;
    string color;

public:
    void Info(string name,string weight,string color);
    void show_info();
    void sit();
    void roll();

};


#endif //CLIENT_H_    // 避免重复声明

出现报错:

 

 

解决:

在头文件中添加:

#include <string>
using namespace std;

 

Guess you like

Origin blog.csdn.net/Kefenggewu_/article/details/121181991