title: read and write file in chunks of bytes in c++
body: <p>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?</p>
  
  <pre><code>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 &lt;&lt; size &lt;&lt; endl;
  
      ofstream obj;
      obj.open("new.txt");
  
      while (!is.eof())
      {
          for (; i &lt;= size;)
          {
              is.seekg(i, is.beg);
              int sz = is.tellg();
              // cout&lt;&lt;sz&lt;&lt;endl;
  
              data = new char[sz + 1]; //  for the '\0'
              is.read(data, sz);
  
              data[sz] = '\0'; // set '\0' 
              cout &lt;&lt; " data size: " &lt;&lt; strlen(data) &lt;&lt; "\n";
              cout &lt;&lt; data;
              i = i + 10;
          }
          obj.close();
      }
  }
  </code></pre>