title: saving file with ofstream
body: <p>I'm new to C++, I have an image named "test.jpg", i convert it to base64 and decode it again like this:</p>
  
  <pre><code>std::ifstream  inputFile;
  inputFile.open("test.jpg",std::ios::binary);
  std::filebuf* pbuf = inputFile.rdbuf();
  
  inputFile.seekg (0, ios::end);
  int length = inputFile.tellg();
  
  // allocate memory to contain file data
   char* buffer=new char[length];
  
  // get file data
  pbuf-&gt;sgetn (buffer,length);
  inputFile.close();
  CBase64 base64;
  string encodedData = base64.base64_encode((unsigned char*)buffer,length);
  delete[] buffer;
  
  string decodedData = base64.base64_decode(encodedData);
  
  ofstream outPutFile;
  outPutFile.open("test2.jpg",ios::binary | ios::out);
  outPutFile.write(decodedData.c_str(), decodedData.length());
  outPutFile.close();
  </code></pre>
  
  <p>the "test2.jpg" has exact same size as "test.jpg"(the original file) but, i can't open it.
  i couldn't find what is the problem.</p>