title: convert a file (.txt,.pdf..) into a stream file
body: <p>I would like to ask what is the easiest and faster way to convert a file into a stream file.</p>
  
  <p>I did the following :</p>
  
  <pre><code>//convert to stream:
  std::string fil= "/home/file.pdf";
  
  std::ifstream t(fil.c_str());
  if (t)
  {
    string res;
    string line;
    while (getline(t, line, '\n'))
    {
      res=res+line;
    }
    std::string p;
    p=(base64_encode((reinterpret_cast&lt;const unsigned char *&gt; (res.c_str())),res.size()));
    std::string data=p;
  
    char *token = strtok( const_cast&lt;char*&gt;(fil.c_str() ), "/" );
    std::string name;
    std::vector&lt;int&gt; values;
  
    while ( token != NULL )
    {
      name=token;
      token = strtok( NULL, "/" );
    }
    std::string f_name=name;
  }
  
  //convert from stream to file
  ofstream myfile;
  
  std::string fil;
  
  ofstream file (fil.c_str(), ios::out | ios::binary);
  std::string content = base64_decode(f_data);
  file.write ((char*)&amp;content, sizeof(content));
  file.close();
  </code></pre>
  
  <p>Is this the easiest way?! Is there a posibility to upgrade my code?</p>
  
  <p>EDIT</p>
  
  <p>Code works for .cpp or .txt files. It doesn't work for .pdf files. why?</p>