私はこれをやろうとしています:
#include <string>
class Medicine{
string name;
};
しかし、まったく機能していません。プロジェクトを右クリックしてみました->インデックス->未解決のインクルードを検索しました。std::string でも機能しません。私は何をすべきか?
string
属する名前空間で完全修飾する必要があります ( std
):
#include <string>
class Medicine {
std::string name;
// ^^^^^
};
またはusing
宣言を使用します。
#include <string>
using std::string; // <== This will allow you to use "string" as an
// unqualified name (resolving to "std::string")
class Medicine {
string name;
// ^^^^^^
// No need to fully qualify the name thanks to the using declaration
};
(ヘッダーのstring
) クラスは std 名前空間内で定義されます。オブジェクト宣言で欠落しているusing std::string;
か、std::
前にあります。string
それでも修正できない場合は、この回答をご覧ください。