include - "seekg identifier not found" -


मेरे पास मुख्य नामक एक कार्यक्रम है:

  # include & lt; iostream & gt; # से & lt में शामिल हैं, fstream & gt; नेमस्पेस एसटीडी का उपयोग करना; #include "other.h" int main () {// do stuff}  

और फिर other.h:

  char * load_data (int start_point) , Int num_characters) {seekg (begin_point); Char * return_val = नया char [num_characters + 1]; mapdata.getline (return_val, NUM_CHARACTERS); वापसी वापसी_वल; }  

और मुझे त्रुटि मिलती है:

'seekg': पहचानकर्ता नहीं मिला

मुझे क्यों मिलता है यह त्रुटि और मैं इसे कैसे ठीक करूं?

seekg fstream से एक विधि है (istream में घोषित) वर्ग।

आपने किसी भी प्रारंभिक नहीं किया है।

इसे एक उदाहरण के रूप में लेना

  ifstream है; Is.open ("test.txt", आईओएस :: द्विआधारी); // फ़ाइल की लंबाई प्राप्त करें: is.seekg (0, ios :: अंत);  

स्रोत:

तो, आपको चाहिए

  char * load_data (int start_point, int num_characters) {ifstream है; है ("yourfile.txt") // फ़ाइल अब पढ़ने के लिए खुली है। seekg (begin_point); Char * return_val = नया char [num_characters + 1]; mapdata.getline (return_val, NUM_CHARACTERS); वापसी वापसी_वल; }  

अपने प्रश्न में जो पैराओक्सन ने टिप्पणी की है उसे ध्यान में रखें।

आपको फ़ंक्शन के load_data कार्यान्वयन वाले अन्य फ़ाइल को बनाना चाहिए। फ़ाइल other.h में फ़ंक्शन के load_data घोषणा होना चाहिए। उस फाइल (अन्य एच) में आपको काम करने के लिए वहां घोषित कार्यों के लिए सभी फाइलें शामिल करनी चाहिए। और खुद को कई के खिलाफ की रक्षा करना भूल जाते हैं!

फाइल अन्य।

  #ifndef __OTHER_H__ #define __OTHER_H__ #include & lt; iostream & gt; # शामिल करें & lt; fstream & gt; Char * load_data (int, int); // कोई कार्यान्वयन #endif  

अन्य.cpp फ़ाइल

  # include "other.h" / / मानता है अन्य.h और other.cpp समान निर्देशिका में चार * लोड_डेटा (int शुरू, int राशि) {// load_data कार्यान्वयन}  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -