basic_streambuf::pubseekpos
basic_streambuf::pubseekpos
Determine and move to a desired offset.
pos_type pubseekpos
(pos_type sp,
ios_base::openmode which = ios::in |ios::out);
The function
pubseekpos() is use to move to a desired offset using a type
pos_type, which holds all necessary information.
Returns a
pos_type via
seekpos(sb, which)
pubseekoff(), seekoff()
// The file ewl-test contains:
// ABCDEFGHIJKLMNOPQRSTUVWXYZ
#include <iostream>
#include <fstream>
#include <cstdlib>
int main()
{
using namespace std;
ifstream in("ewl-test");
if(!in.is_open())
{cout << "could not open file"; exit(1);}
streampos spEnd(0), spStart(0), aCheck(0);
spEnd = spStart = 5;
aCheck = in.rdbuf()->pubseekpos(spStart,ios::in);
cout << "The offset at the start of the reading"
<< " in bytes is "
<< static_cast<streamoff>(aCheck) << endl;
char ch;
while(spEnd != spStart+10)
{
in.get(ch);
cout << ch;
spEnd = in.rdbuf()->pubseekoff(0, ios::cur);
}
aCheck = in.rdbuf()->pubseekoff(0,ios::cur);
cout << "\nThe final position's offset"
<< " in bytes now is "
<< static_cast<streamoff>(aCheck) << endl;
in.close();
return 0;
}
Result:
The offfset for the start of the reading in bytes is 5
FGHIJKLMNO
The final position's offset in bytes now is 15