File pointers and stream manipulation c++ In Hindi

File pointers and stream manipulation c++ In Hindi

C++ प्रोग्रामिंग लैंग्वेज में यूजर डिफाइन फ़ाइल पॉइंटर्स और स्ट्रीम मैनिपुलेशन फंक्शन C++ यूजर को फाइल हैंडलिंग में टेक्स्ट और इनफार्मेशन को रीड और राइट फ़ाइल इनपुट और आउटपुट ऑपरेशन पर अधिक कंट्रोल प्रोवाइड करते हैं. स्पेशली, जब C++ यूजर को फाइल हैंडलिंग ऑपरेशन में मौजूदा टेक्स्ट और बाइनरी फ़ाइलों के अंदर डेटा को नेविगेट, मॉडिफ़ाई, या फ़ॉर्मेट करने की आवश्यकता होती है।

File pointers and stream manipulation c++ In Hindi

C++ प्रोग्राम फाइल हैंडलिंग में फ़ाइल पॉइंटर्स का यूज़ मौजूदा फ़ाइल को रीड करने या राइट करते समय उसकी मौजूदा जगह को मैनेज करने में किया जाता है।

C++ प्रोग्राम में स्ट्रीम मैनिपुलेटर्स फीचर्स C++ यूजर को फाइल इनपुट और आउटपुट के फ़ॉर्मेट (जैसे, प्रिसिजन, अलाइनमेंट, स्पेस भरना) आदि को कंट्रोल और मैनेज करने में हेल्प करते हैं।

File Pointers Concept in C++.

जब C++ यूजर फाइल हैंडलिंग में किसी फ़ाइल स्ट्रीम्स (ifstream, ofstream, fstream) क्लास लाइब्रेरी को डील कर रहे होते हैं. तो फ़ाइल पॉइंटर (जिसे फ़ाइल कर्सर के रूप में भी जाना जाता है) मौजूदा फ़ाइल के अंदर डाटा और इनफार्मेशन को रीड या राइट करने के लिए डिफ़ॉल्ट रूप से मौजूदा स्पेस को इंडीकेट करता है।

फाइल हैंडलिंग में फाइल इनपुट ऑपरेशन्स टास्क के लिए, फ़ाइल पॉइंटर फ़ाइल को फाइल में स्टार्ट से स्टार्ट किया जाता है।

फाइल हैंडलिंग में आउटपुट ऑपरेशन्स टास्क के लिए, फ़ाइल पॉइंटर अंत में (यदि C++ यूजर डाटा और इनफार्मेशन को ऐड कर रहे हैं), या स्टार्ट में (यदि C++ यूजर फाइल में ओवरराइट कर रहे हैं) यह स्टार्ट में होता है।

Common file handling file pointer operation types.

  • seekg – फाइल हैंडलिंग में इनपुट फाइल ऑपरेशन टास्क (get) स्ट्रीम्स के लिए फ़ाइल पॉइंटर को मूव करता है।
  • seekp – फाइल हैंडलिंग में आउटपुट फाइल ऑपरेशन टास्क (put) स्ट्रीम्स के लिए फ़ाइल पॉइंटर को मूव करता है।
  • tellg – फाइल हैंडलिंग में इनपुट स्ट्रीम फाइल के लिए फ़ाइल पॉइंटर की मौजूदा जगह को इंडीकेट करता है।
  • tellp – फाइल हैंडलिंग में आउटपुट स्ट्रीम के लिए फ़ाइल पॉइंटर की मौजूदा जगह को इंडीकेट करता है।

Moving the file pointer with the seekg() and seekp() functions in file handling.

ये फ़ंक्शन C++ यूजर को फाइल हैंडलिंग में फ़ाइल पॉइंटर को किसी स्पेसिफिक लोकेशन पर मूव करने में हेल्प करते हैं। फाइल हैंडलिंग में seekg() और seekp() दोनों आर्गुमेंट वैल्यू इनपुट लेते हैं.

ऑफ़सेट फाइल हैंडलिंग में फाइल पॉइंटर को मूव करने के लिए बाइट्स की नंबर्स है।

डायरेक्शन यह ios::beg (शुरुआत), ios::cur (मौजूदा फाइल जगह), या ios::end (फ़ाइल का अंत लोकेशन) इंडिकेशन स्पेस हो सकता है।

Syntax of seekg() and seekp() in C++ file handling.

streampos seekg (streampos offset, ios_base::seekdir dir);

streampos seekp (streampos offset, ios_base::seekdir dir);

Example of moving the file pointer with seekg().

#include <iostream>

#include <fstream>

using namespace std;

int main() {

    // here we open the file in read mode for operation

    ifstream inFile(“samplefile.txt”);

    if (!inFile) {

        cout << “Display Error during samplefile text file opening.” << endl;

        return 1;

    }

    // here it move file pointer to the 9th byte position from the beginning

    inFile.seekg(9, ios::beg);

    // hear it read the rest of the file starting from the new position location

    string textline;

    getline(inFile, textline);  // here it Will read from the 10th byte location

    cout << “Here it Read from file after seeking position. ” << textline << endl;

    inFile.close();

    return 0;

}

Example of moving the file pointer with seekg().

  • यहाँ इस एक्साम्प्ल में inFile.seekg(9, ios::beg) फ़ाइल पॉइंटर को फ़ाइल की स्टार्ट  से 9वें बाइट लोकेशन पर मूव करता है।
  • उसके बाद, आपका प्रोग्राम उस जगह से टेक्स्ट इनफार्मेशन को रीड करता है।

Example of moving the file pointer (writing to a file) with seekp() in file handling.

#include <iostream>

#include <fstream>

using namespace std;

int main() {

    // here it open the file in both input and output processing mode

    fstream file(“samplefile.txt”, ios::in | ios::out);

    if (!file) {

        cout << “Display Error during file opening.” << endl;

        return 1;

    }

    // here it move the file pointer to the 7th byte from the beginning for writing purpose

    file.seekp(7, ios::beg);

    // here it write at the new position location

    file << “Put Desire Text Information”;

    file.close();

    return 0;

}

Explanation of moving the file pointer (writing to a file) with seekp().

  • यहाँ इस एक्साम्प्ल में file.seekp(7, ios::beg) मेथड आउटपुट फ़ाइल पॉइंटर को स्टार्ट से 7th बाइट पर मूव करता है।
  • फिर, यह इसके बाद उस जगह पर “Put Desire Text Information” टेक्स्ट इनफार्मेशन को लिखता है, हो सकता है, यह मौजूदा फाइल कंटेंट को ओवरराइट कर देता है।

The concept of tellg() and tellp() in C++ file handling.

ये फ़ंक्शन C++ यूजर को फाइल हैंडलिंग में फ़ंक्शन tellg() और tellp() फ़ाइल पॉइंटर की मौजूदा स्पेस लोकेशन को प्रोग्राम में इंडीकेट करते हैं।

tellg() and tellp() syntax in C++.

streampos tellg();

streampos tellp();

यहाँ इस सिंटेक्स में tellg() फंक्शन फाइल इनपुट पॉइंटर (ifstream/fstream) की स्पेस लोकेशन को इंडीकेट करते है।

यह फंक्शन tellp() आउटपुट पॉइंटर (ofstream/fstream) की स्पेस लोकेशन को इंडीकेट करते है।

Example of getting the location of the current file pointer in a C++ program.

#include <iostream>

#include <fstream>

using namespace std;

int main() {

    // here it open the file in read mode for processing purpose

    ifstream inFile(“samplefile.txt”);

    if (!inFile) {

        cout << “Display Error during file opening.” << endl;

        return 1;

    }

    // here it read some data from the above file

    char chartr;

    inFile.get(chartr);  // here it read one character from file

    // here it get current position in the above file

    streampos pos = inFile.tellg();

    cout << “Here is the Current file pointer locaion is ” << pos << endl;

    inFile.close();

    return 0;

}

Explanation of the concept of tellg() and tellp() in C++ file handling.

  • यहाँ इस एक्साम्प्ल में inFile.get(chartr) के साथ मौजूदा फाइल में एक कैरेक्टर रीड करने के बाद, tellg() फंक्शन फ़ाइल पॉइंटर की करंट पोज़िशन बाइट्स में रिटर्न करता है।

Leave a Reply