This may just be a simple mistake that I'm not seeing, but I think I'm simply doing something wrong. Don't worry I'm not using namespace std in my header functions or anything which seemed to be this person's issue [Question I read similar to mine][1] [1]: Why am I getting string does not name a type Error?
这可能只是我没看到的一个简单的错误,但我认为我只是做错了什么。不要担心,我在头函数中没有使用命名空间std,或者任何看起来是这个人的问题(我读过类似的问题)[1][1]:为什么我得到的字符串没有命名一个类型错误?
I am getting 4 errors right now:
我现在有4个错误:
C:\Documents and Settings\Me\My Documents\C++Projects\C++\RandomSentence\Nouns.h|8|error: 'string' in namespace 'std' does not name a type|
C:\Documents and Settings\Me\My文件\ \ c++项目c++ \ RandomSentence \名词。h|8|错误:命名空间“std”中的“string”没有命名|类型
C:\Documents and Settings\Me\My Documents\C++Projects\C++\RandomSentence\Nouns.h|12|error: 'string' in namespace 'std' does not name a type|
C:\Documents and Settings\Me\My文件\ \ c++项目c++ \ RandomSentence \名词。h|12|错误:命名空间“std”中的“string”没有命名|类型
C:\Documents and Settings\Me\My Documents\C++Projects\C++\RandomSentence\Nouns.h|13|error: 'string' in namespace 'std' does not name a type|
C:\Documents and Settings\Me\My文件\ \ c++项目c++ \ RandomSentence \名词。h|13|错误:命名空间“std”中的“string”没有命名|类型
C:\Documents and Settings\Me\My Documents\C++Projects\C++\RandomSentence\Nouns.cpp|9|error: no 'std::string Nouns::nounGenerator()' member function declared in class 'Nouns'|
C:\Documents and Settings\Me\My文件\ \ c++项目c++ \ RandomSentence \名词。cpp|9|错误:没有std::string名词::名词生成器()在类名词|中声明的成员函数。
||=== Build finished: 4 errors, 0 warnings ===|
||===构建完成:4个错误,0个警告==|
Here is my header file:
这是我的头文件:
class Nouns
{
public:
Nouns();
std::string noun;
protected:
private:
int rnp; // random noun picker
std::string dog, cat, rat, coat, toilet, lizard, mime, clown, barbie, pig, lamp, chair, hanger, pancake, biscut, ferret, blanket, tree, door, radio;
std::string nounGenerator()
};
And this is my cpp file:
这是我的cpp文件
#include "Nouns.h"
#include <iostream>
Nouns::Nouns()
{
}
std::string Nouns::nounGenerator(){
RollRandom rollRandObj;
rnp = rollRandObj.randNum;
switch(rnp){
case 1:
noun = "dog";
break;
case 2:
noun = "cat";
break;
case 3:
noun = "rat";
break;
case 4:
noun = "coat";
break;
case 5:
noun = "toilet";
break;
case 6:
noun = "lizard";
break;
case 7:
noun = "mime";
break;
case 8:
noun = "clown";
break;
case 9:
noun = "barbie";
break;
case 10:
noun = "pig";
break;
case 11:
noun = "lamp";
break;
case 12:
noun = "chair";
break;
case 13:
noun = "hanger";
break;
case 14:
noun = "pancake";
break;
case 15:
noun = "biscut";
break;
case 16:
noun = "ferret";
break;
case 17:
noun = "blanket";
break;
case 18:
noun = "tree";
break;
case 19:
noun = "door";
break;
case 20:
noun = "radio";
break;
}
return noun;
}
3 个解决方案
#1
55
You need to
你需要
#include <string>
<iostream>
declares cout
, cin
, not string
.
#2
6
Nouns.h
doesn't include <string>
, but it needs to. You need to add
名词。h不包含
#include <string>
at the top of that file, otherwise the compiler doesn't know what std::string
is when it is encountered for the first time.
在该文件的顶部,否则编译器不知道第一次遇到std::string是什么。
#3
3
You need to add:
你需要添加:
#include <string>
In your header file.
在你的头文件。
#1
55
You need to
你需要
#include <string>
<iostream>
declares cout
, cin
, not string
.
#2
6
Nouns.h
doesn't include <string>
, but it needs to. You need to add
名词。h不包含
#include <string>
at the top of that file, otherwise the compiler doesn't know what std::string
is when it is encountered for the first time.
在该文件的顶部,否则编译器不知道第一次遇到std::string是什么。
#3
3
You need to add:
你需要添加:
#include <string>
In your header file.
在你的头文件。