नाम नहीं है यह एक साधारण गलती हो सकती है जिसे मैं नहीं देख रहा हूं, लेकिन मुझे लगता है कि मैं बस कुछ गलत कर रहा हूं। चिंता मत करो मैं अपने शीर्षक में नाम स्थान एसटीडी का उपयोग नहीं कार्यों या जो कुछ भी इस व्यक्ति के मुद्दे [प्रश्न मैं मेरा के लिए इसी तरह पढ़ा] [1] [1] लग रहा था: Why am I getting string does not name a type Error?नेमस्पेस std में स्ट्रिंग का नाम
मैं 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 Documents\C++Projects\C++\RandomSentence\Nouns.h|12|error: 'string' in namespace 'std' does not name a type|
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 Documents\C++Projects\C++\RandomSentence\Nouns.cpp|9|error: no 'std::string Nouns::nounGenerator()' member function declared in class 'Nouns'|
||=== Build finished: 4 errors, 0 warnings ===|
यहाँ मेरी हेडर फ़ाइल है:
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()
};
और ये मेरे 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;
}
जब कोई सरणी खूबसूरती से काम करेगी तो स्विच का उपयोग क्यों करें? – TheZ
@TheZ: उन चीजों को शामिल न करें जिन्हें आप उपयोग करना चाहते हैं? मुझे संदेह है कि इन प्रश्नों का एक ही जवाब है ... – Sharkos
स्विच वह है जो मुझे उपयोग करने के लिए उपयोग किया जाता है। व्यक्तिगत पसंद। और मेरे लिए यह साफ दिखता है। –