if the stream has not been used yet then the pointer to read the file is automatically at the beginning of the file. My understanding is that once you have read part of the file you can reset the pointer to read the file to the beginning again by using the seekg(0, ios::beg); command. However, if you reach the end of the file before you want to reset the pointer to read the file back to the beginning, then the stream needs to be cleared with the streamName.clear(); command before you can reset the pointer to read the file back to the beginning. This is because finding EOF (which is the terminating condition for your while loop) causes the stream to fail and a failed stream cannot be reset (or reused) until it is cleared.