P
pedagani
I want to copy only a part of the binary file delimited by offset
values say START_OFFSET_ & END_OFFSET_ which can be as huge as a 50
Giga. Below is the program where I could set a START_OFFSET_ but could
not specify the END_OFFSET_ value.
Any thoughts? Please advise. Thanks.
#include <fstream>
#include <iostream>
#include <algorithm>
#include <ios>
#include <iterator>
#include <string>
#define START_OFFSET_ 5000000
#define END_OFFSET_ 10000000
using namespace std;
void main()
{
ifstream is("c:\\test.bin",ios_base::binary);
ofstream os("c:\\testparse.bin",ios_base::binary);
if (!is || !os)
{
cout<<"Could not open the file for read/write";
exit(1);
}
is.seekg(START_OFFSET_,ios::beg);
copy(istream_iterator<char> (is),
istream_iterator<char> (),
ostream_iterator<char> (os));
is.close();
os.close();
/* I wanted to have something like this
//basic_istream<char,char_traits<char> >& start =
is.seekg(START_OFFSET_,ios::beg);
//basic_istream<char,char_traits<char> >& end =
is.seekg(END_OFFSET_,ios::beg);
//copy( istream_iterator<char> (start),
// istream_iterator<char> (end),
// ostream_iterator<char> (os)); //Apparently, this does not work
*/
}
values say START_OFFSET_ & END_OFFSET_ which can be as huge as a 50
Giga. Below is the program where I could set a START_OFFSET_ but could
not specify the END_OFFSET_ value.
Any thoughts? Please advise. Thanks.
#include <fstream>
#include <iostream>
#include <algorithm>
#include <ios>
#include <iterator>
#include <string>
#define START_OFFSET_ 5000000
#define END_OFFSET_ 10000000
using namespace std;
void main()
{
ifstream is("c:\\test.bin",ios_base::binary);
ofstream os("c:\\testparse.bin",ios_base::binary);
if (!is || !os)
{
cout<<"Could not open the file for read/write";
exit(1);
}
is.seekg(START_OFFSET_,ios::beg);
copy(istream_iterator<char> (is),
istream_iterator<char> (),
ostream_iterator<char> (os));
is.close();
os.close();
/* I wanted to have something like this
//basic_istream<char,char_traits<char> >& start =
is.seekg(START_OFFSET_,ios::beg);
//basic_istream<char,char_traits<char> >& end =
is.seekg(END_OFFSET_,ios::beg);
//copy( istream_iterator<char> (start),
// istream_iterator<char> (end),
// ostream_iterator<char> (os)); //Apparently, this does not work
*/
}