[英]C++ Unknown type name 'string'
我正在處理 C++ 頭文件,但不斷收到錯誤消息“未知類型名稱 'string';您的意思是 'std::string'?” #include <string>
已經在我的代碼頂部,所以我不知道如何解決這個問題。 有什么想法嗎? 我正在使用 Xcode,如果這有什么不同的話。
#ifndef POINT_HPP
#define POINT_HPP
#include <string>
using namespace std;
class Point {
public:
Point();
Point(int pInitX, int pInitY);
Point(int pInitX, int pInitY, int pInitColor);
double distance(Point pAnotherPoint);
int getColor();
int getX();
int getY();
void move(int pNewX, int pNewY);
void setColor(int pNewColor);
void setX(int pNewX);
void setY(int pNewY);
string toString; // Error: Unknown type name 'string'; did you mean 'std::string'?
private:
void init(int pInitX, int pInitY, int pInitColor);
int mColor;
int mX;
int mY;
};
#endif
您必須使用std::string toString()
或using namespace std;
聲明using namespace std;
全球
確保還在CMakeLists.txt
設置Point
類(標題和 cpp)的路徑。
如果您使用的是 QT,它應該類似於
set(PROJECT_SOURCES
...
point.cpp
point.h
)
之后,您需要像這樣導入頂部的字符串類#include <string>
然后聲明using namespace std;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.