I have searched for it everywhere, but I can not seem to understand how to use ios::cur. I need to read a whole file in chunks of 10 bytes, write those bytes into a buffer and then write that buffer into another file. For that I send the first 10 bytes, then the next 10 and so on. But how do i make sure the pointer starts from the last iteration's position?
char* data = 0;
int i = 0;
std::ifstream is("test.txt", std::ifstream::binary);
if (is)
{
is.seekg(0, is.end);
int size = is.tellg();
cout << size << endl;
ofstream obj;
obj.open("new.txt");
while (!is.eof())
{
for (; i <= size;)
{
is.seekg(i, is.beg);
int sz = is.tellg();
// cout<<sz<<endl;
data = new char[sz + 1]; // for the '\0'
is.read(data, sz);
data[sz] = '\0'; // set '\0'
cout << " data size: " << strlen(data) << "\n";
cout << data;
i = i + 10;
}
obj.close();
}
}