How to read the whole istream correctly?
<p>Here is a simple code to print all characters of a txt file on screen:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
using namespace std;

int main() {
       int **i;
       int j,k;
       char a;
    ifstream test("test.txt", ios::binary);
    while((a=test.get())!=-1)//if I use "while(!test.eof())" here, how to avoid the output of the last character(-1) to std::cout, or any ostream objects?
    {
   putchar(a);//also change this to putchar(test.get());
    }
       getchar();
}
</code></pre>

<p>As I noted in the code, if I use "test.eof()" to judge the end of test.txt, I'll always get an extra blank at the end of the output. How to avoid it?</p>
