title: Reading a binary file in c++ with stringstream
body: <p>I want to write/read data from a file. Is it possible to divide the file (inside the code) in multiple Strings/Sections? Or read data untill a specific line? </p>
  
  <p>Just like: "Read the Data untill line 32, put it inside a String, read the next 32 lines and put it into another string"</p>
  
  <p>Im already know how to read and find data with seekp but i dont really like it because my code always gets to long. </p>
  
  <p>I already found some code but i dont understand it how it works:</p>
  
  <pre><code>dataset_t* DDS::readFile(std::string filename)
  {
  dataset_t* dataset = NULL;
  
  std::stringstream ss;
  std::ifstream fs;
  uint8_t tmp_c;
  
  try
  {
      fs.open(filename.c_str(), std::ifstream::in);
  
      if (!fs)
      {
          std::cout &lt;&lt; "File not found: " &lt;&lt; filename &lt;&lt; std::endl;
          return NULL;
      }
  
      while(fs.good())
      {
          fs.read((char*)&amp;tmp_c, 1);
          if (fs.good()) ss.write((char*)&amp;tmp_c, 1);
      }
      fs.close();
  
      dataset = new dataset_t();
  
      const uint32_t bufferSize = 32;
      char* buffer = new char[bufferSize];
  
      uint32_t count = 1;
      while(ss.good())
      {
          ss.getline(buffer, bufferSize);
  
          dataitem_t dataitem;
          dataitem.identifier = buffer;
          dataitem.count = count;
          dataset-&gt;push_back(dataitem);
  
          count++;
      }
  
      return dataset;
  }
  catch(std::exception e)
  {
      cdelete(dataset);
      return NULL;
  }
  
  }
  </code></pre>
  
  <p>The Code edits a binary save file.</p>
  
  <p>Or can someone link me a website where i can learn more about buffers and stringstreams?</p>