32-bit checksum of a file
First of all, your checksum function should probably be named checksum and actually return the checksum, rather than simply printing it.

Now, you're not taking advantage of what the std::basic_ifstream API actually gives you. First, read() returns a basic_istream&amp;, which is convertible to bool. That bool tells you if the complete read succeeded or not. So all you have to do is:

uint32_t checksum(std::ifstream&amp; file) 
{
    uint32_t sum = 0;

    uint32_t word = 0;
    while (file.read(reinterpret_cast&lt;char*&gt;(&amp;word), sizeof(word))) {
        sum += word;
    }

    // ??


Now, when read() fails, that means our file has run out (assuming we had a valid file to begin with). But, we have other information. There is also gcount() which 


  Returns the number of characters extracted by the last unformatted input operation.


If the read partially succeeded, we can mask off the other bytes and add the remainder. Thus, the full solution might be:

uint32_t checksum(std::ifstream&amp; file) 
{
    uint32_t sum = 0;

    uint32_t word = 0;
    while (file.read(reinterpret_cast&lt;char*&gt;(&amp;word), sizeof(word))) {
        sum += word;
    }

    if (file.gcount()) {
        word &amp;= (~0U &gt;&gt; ((sizeof(uint32_t) - file.gcount()) * 8));
        sum += word;
    }

    return sum;
}


Doing the masking looks kind of terrible though, so instead we could simply zero out word every time so we can just add the result:

uint32_t checksum(std::ifstream&amp; file) 
{
    uint32_t sum = 0;

    uint32_t word = 0;
    while (file.read(reinterpret_cast&lt;char*&gt;(&amp;word), sizeof(word))) {
        sum += word;
        word = 0;
    }

    sum += word; // add the last word, could be 0
                 // if the file size is divisible by 4

    return sum;
}