JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi sociology physics physical education maths english economics geography History

chemistry business studies biology accountancy political science

Class 12

Hindi physics physical education maths english economics

chemistry business studies biology accountancy Political science History sociology

Home science Geography

English medium Notes

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Class 12

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Categories: c++ language in hindi

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 के बाद होता है |

Sbistudy

Recent Posts

four potential in hindi 4-potential electrodynamics चतुर्विम विभव किसे कहते हैं

चतुर्विम विभव (Four-Potential) हम जानते हैं कि एक निर्देश तंत्र में विद्युत क्षेत्र इसके सापेक्ष…

22 hours ago

Relativistic Electrodynamics in hindi आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा

आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा Relativistic Electrodynamics in hindi ? अध्याय : आपेक्षिकीय विद्युतगतिकी…

3 days ago

pair production in hindi formula definition युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए

युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए pair production in hindi formula…

5 days ago

THRESHOLD REACTION ENERGY in hindi देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा

देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा THRESHOLD REACTION ENERGY in hindi…

5 days ago

elastic collision of two particles in hindi definition formula दो कणों की अप्रत्यास्थ टक्कर क्या है

दो कणों की अप्रत्यास्थ टक्कर क्या है elastic collision of two particles in hindi definition…

5 days ago

FOURIER SERIES OF SAWTOOTH WAVE in hindi आरादंती तरंग की फूरिये श्रेणी क्या है चित्र सहित

आरादंती तरंग की फूरिये श्रेणी क्या है चित्र सहित FOURIER SERIES OF SAWTOOTH WAVE in…

1 week ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now