istream_iterator
uses operator >>
to read elements, but operator >>
skip whitespaces.
You may try using noskipws
inputfile >> noskipws;
§ 24.6.1 p1. (my emphasis)
The class template
istream_iterator
is an input iterator (24.2.3) that reads (using operator>>) successive elements from the input stream for which it was constructed....