File Position Pointers , what is file position pointer in c++ in hindi with example program source code

what is file position pointer in c++ in hindi with example program source code , File Position Pointers :-
इससे पहले के article मे file के basic operation open , read और write को discuss किया है अब इस article मे file से related कुछ advance concept को discuss करेगे |
File Position Pointers
दोनों ही file class istream and ostream  का use किसी file-position pointer को  position को set करने के लिए किया जाता है  इस memberfunction को निन्म class function के साथ किया जाता है :-
istream के लिए seekg (“seek get”) को use किया जाता है
और ostream के लिए seekp (“seek put”) का use किया जाता है |
दोनों ही argument long integer होता है | और second argument का use seek direction को indicate करने के लिए किया जाता है |
seek direction ios::beg (the default) का use किसी stream के begining की position को define करने के लिए किया जाता है |
ios::cur का use किसी stream के current position को define करने के लिए किया जाता है |
ios::end का use किसी stream को end position को define करने के लिए किया जाता है |
file position pointer एक integer है जो की किसी file की location define करता है | इसमें file की location को bytes मे define करता है | और इस file pointer मे जहा से file start होती है यहा से file location को सेव किया जाता है |
उदाहरन :
इस उदाहरणों मे किसी file pointer “f” से position को set करने के लिए किया जाता है :-
// position to the nth byte of fileObject (assumes ios::beg)
fileObject.seekg( n ) : इस syntax से किसी file object को nth byte मे position को set किया जाता है |
इसका code निन्म है
इस code से किसी file मे input stream से position को set करने के लिए किया जाता है | इस syntax से जब किसी file मे extract input stream से next position को file pointer को set किया जाता है | इसके operation  निन्म उदाहरन से समज सकते है :-
Input : “Good Morning”
Output: Morning
इस statement मे दो तरन syntax होते है :-
istream&seekg(streampos position);
istream&seekg(streamoff offset, ios_base::seekdir dir);
यहा पर
position : ये stream buffer मे किसी position को डेफिन करता है  |
offset : ये integer value जिसका type streamoff है | इसका use किसी stream buffer को stop करने  के लिए किया जाता है |
dir : ये  seeking की direction को define करता है | इसका मतलब है इसमें left और right position को set व्कारना है | इसमें मुख्य तीन डायरेक्शन होती है :-
ios_base::beg (offset from the beginning of the stream’s buffer): ये stream की begining को define करता है |
ios_base::cur (offset from the current position in the stream’s buffer): ये stream के current position को define करता है |
ios_base::end (offset from the end of the stream’s buffer): ये stream के end position को डेफिन करता है |
Code –
// Code to demonstrate the seekg function in file handling from begining position
#include <fstream>
#include <iostream>
using namespace std;
int main (int argc, char** argv)
{
fstream File(“data.txt”, ios::in | ios::out | ios::trunc); // file open statement that open file with turncating mode
// Add the characters “Hello World” to the file
File << “Good Morning”;
File.seekg(6, ios::beg); // Seek to 6 characters from the beginning of the file
char a[6]; // Read the next 5 characters from the file into a buffer
File.read(a, 5);
A[5] = 0;
cout << buffer << endl;
File.close();
}
इस उदाहरन मे File.seekg(6, ios::beg); से seek operation stream की start से start होता हैउदहारण 2 :-
// Code to demonstrate the seekg function in file handling from current position
#include <fstream>
#include <iostream>
using namespace std;
int main (int argc, char** argv)
{
fstream File(“data.txt”, ios::in | ios::out | ios::trunc); // file open statement that open file with turncating mode
// Add the characters “Good Morning” to the file
File << “Good Morning”;
cin>>a[5];
File.seekg(3, ios::current ); // Seek to 3 characters from the beginning of the file
char a[4]; // Read the next 4 characters from the file into a buffer
File.read(a, 4);
A[5] = 0;
cout << buffer << endl;
File.close();
}
इस उअदाहर मे दबसे पहले file मे से 5 charecter को पहले ही read कर चुके है इसके बाद seekg() operation को call किया है जिसमे current position से 3 next position को set कर दिया है और बाद मे 4 charecter को read किया गया है |उदाहरन 3 :
// Code to demonstrate the seekg function in file handling from end position
#include <fstream>
#include <iostream>
using namespace std;
int main (int argc, char** argv)
{
fstream File(“data.txt”, ios::in | ios::out | ios::trunc); // file open statement that open file with turncating mode
// Add the characters “Good Morning” to the file
File << “Good Morning”;
File.seekg(3, ios::end ); // Seek to 3 characters from the beginning of the file
char a[4]; // Read the next 4 characters from the file into a buffer
File.read(a, 4);
A[5] = 0;
cout << buffer << endl;
File.close();
}
इस उदाहरन मे , file की seek को file stream के end मे से start किया जाता है | और इसमें back side मे seeking operation होता है | अतः इसमें Good Morning मे Good Morn(file pointer )ing set होगा |

उदहारण 4 :

// Code to demonstrate the seekg function in file handling from end position
#include <fstream>
#include <iostream>
using namespace std;
int main (int argc, char** argv)
{
fstream File(“data.txt”, ios::in | ios::out | ios::trunc); // file open statement that open file with turncating mode
// Add the characters “Good Morning” to the file
File << “Good Morning”;
File.seekg(]0, ios::end ); // Seek to 3 characters from the beginning of the file
char a[4]; // Read the next 4 characters from the file into a buffer
File.read(a, 4);
A[5] = 0;
cout << buffer << endl;
File.close();
}
इस code मे file pointer file stream के end position मे set हो जाता है ओर इसके बाद किये गये input और output operation को file के end position के बाद होता है |