title: What is the idiomatic C++17 standard approach to reading binary files?
body: <p>Normally I would just use C style file IO, but I'm trying a modern C++ approach, including using the C++17 specific features <code>std::byte</code> and <code>std::filesystem</code>.</p>
  
  <p>Reading an entire file into memory, traditional method:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  char *readFileData(char *path)
  {
      FILE *f;
      struct stat fs;
      char *buf;
  
      stat(path, &amp;fs);
      buf = (char *)malloc(fs.st_size);
  
      f = fopen(path, "rb");
      fread(buf, fs.st_size, 1, f);
      fclose(f);
  
      return buf;
  }
  </code></pre>
  
  <p>Reading an entire file into memory, modern approach:</p>
  
  <pre><code>#include &lt;filesystem&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  using namespace std;
  using namespace std::filesystem;
  
  auto readFileData(string path)
  {
      auto fileSize = file_size(path);
      auto buf = make_unique&lt;byte[]&gt;(fileSize);
      basic_ifstream&lt;byte&gt; ifs(path, ios::binary);
      ifs.read(buf.get(), fileSize);
      return buf;
  }
  </code></pre>
  
  <p>Does this look about right? Can this be improved?</p>