I did something like that once.
I checked to see if the char value was between the hex values for 'a' and 'z', then if it was I would subtract 0x20 as that would convert a lowercase letter to capital. The reverse was done for capital letters.
gustgulkan is right, and the underlying reason is that fstream has only one position, shared for both reading and writing (which is a limitation of the underlying C API). When you read a character, you advance the file pointer, and when you write a character, you advance it again.
Other streams (stringstream, for example) have two independent positions, and your approach works:
gustgulkan is right, and the underlying reason is that fstream has only one position, shared for both reading and writing (which is a limitation of the underlying C API). When you read a character, you advance the file pointer, and when you write a character, you advance it again.
So I guess this is why std::iostream_iterator and std::iostreambuf_iterator don't exist.
Edit: hmm, then again such iterators would be a bit clumsy.