title: returning back file's data from server to client - reg
body: <p>I am just trying to implement a simple web server in C++. For that depending on the request the web server fetches data from server. For that I am using</p>
  
  <pre><code>int main()
  {
  std::ifstream file("/home/chaitanya/cpp/net/hello");
  int length;
  char *buffer;
  
  if(file.is_open())
  {
      std::cout &lt;&lt; "File is open\n";
  
      file.seekg(0, std::ios::end);
      length = file.tellg();      
      file.seekg(0, std::ios::beg);
  
      buffer = new char[length];
  
      file.read(buffer, length);
      file.close();   
  }   
  
  printf("Data:\n\n%s\n", buffer);
  delete[] buffer;
  
  return 0;
  }
  </code></pre>
  
  <p>This working fine for small files. Even i am sending the whole file data irrespective of its size thru the socket. Is it a better approach ? </p>
  
  <p>For instance, if file size is huge ? I guess it would be better to send a specific chunk of data at a time. </p>
  
  <p>Can u guys plz suggest as to which approach would be good (or) any other better/faster approaches used by web servers ?</p>
  
  <p>Thanks in advance. :)</p>