Efficient Binary Streaming
<p>I'm looking to stream blocks of 16-bit integers into a program. (Could be from a file or standard input, whatever.) Being as concise as possible, my starting point counts the octets input into the program:</p>

<pre><code>#include &lt;cassert&gt;
#include &lt;cstdint&gt;
#include &lt;iostream&gt;
int main() {
    int16_t samples[768];
    while (std::cin.good()) {
        std::cin.read(reinterpret_cast&lt;char *&gt;(samples), sizeof(samples));
        if (std::cin.gcount() == sizeof(samples)) {
            // ...
        }
    }
    assert(std::cin.eof());
    return 0;
}
</code></pre>

<p>While this works, I want to make sure I'm not missing some more C++ method of performing the same function. (Create a std::vector and read directly into its memory space?) This is supposed to be efficient so I assume that reading a single 16-bit integer at a time and appending to a vector would be out of the question.</p>

<p>Thoughts?</p>
