 <p>Don't use the basic_ifstream as it requires specializtion.</p> <p>Using a static buffer:</p> <pre><code>linux ~ $ cat test_read.cpp #include &lt;fstream&gt; #include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;string&gt; using namespace std; int main( void ) { string filename("file"); size_t bytesAvailable = 128; ifstream inf( filename.c_str() ); if( inf ) { unsigned char mDataBuffer[ bytesAvailable ]; inf.read( (char*)( &amp;mDataBuffer[0] ), bytesAvailable ) ; size_t counted = inf.gcount(); cout &lt;&lt; counted &lt;&lt; endl; } return 0; } linux ~ $ g++ test_read.cpp linux ~ $ echo "123456" &gt; file linux ~ $ ./a.out 7 </code></pre> <p>using a vector:</p> <pre><code>linux ~ $ cat test_read.cpp #include &lt;fstream&gt; #include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;string&gt; using namespace std; int main( void ) { string filename("file"); size_t bytesAvailable = 128; size_t toRead = 128; ifstream inf( filename.c_str() ); if( inf ) { vector&lt;unsigned char&gt; mDataBuffer; mDataBuffer.resize( bytesAvailable ) ; inf.read( (char*)( &amp;mDataBuffer[0]), toRead ) ; size_t counted = inf.gcount(); cout &lt;&lt; counted &lt;&lt; " size=" &lt;&lt; mDataBuffer.size() &lt;&lt; endl; mDataBuffer.resize( counted ) ; cout &lt;&lt; counted &lt;&lt; " size=" &lt;&lt; mDataBuffer.size() &lt;&lt; endl; } return 0; } linux ~ $ g++ test_read.cpp -Wall -o test_read linux ~ $ ./test_read 7 size=128 7 size=7 </code></pre> <p>using reserve instead of resize in first call:</p> <pre><code>linux ~ $ cat test_read.cpp #include &lt;fstream&gt; #include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;string&gt; using namespace std; int main( void ) { string filename("file"); size_t bytesAvailable = 128; size_t toRead = 128; ifstream inf( filename.c_str() ); if( inf ) { vector&lt;unsigned char&gt; mDataBuffer; mDataBuffer.reserve( bytesAvailable ) ; inf.read( (char*)( &amp;mDataBuffer[0]), toRead ) ; size_t counted = inf.gcount(); cout &lt;&lt; counted &lt;&lt; " size=" &lt;&lt; mDataBuffer.size() &lt;&lt; endl; mDataBuffer.resize( counted ) ; cout &lt;&lt; counted &lt;&lt; " size=" &lt;&lt; mDataBuffer.size() &lt;&lt; endl; } return 0; } linux ~ $ g++ test_read.cpp -Wall -o test_read linux ~ $ ./test_read 7 size=0 7 size=7 </code></pre> <p>As you can see, without the call to .resize( counted ), the size of the vector will be wrong. Please keep that in mind. it is a common to use casting see <a href="http://www.cppreference.com/wiki/io/read" rel="nofollow noreferrer">cppReference</a></p>