I don't think you have to read the file twice, might be useful to have a few vectors though:
1. get your values and store them in a vector.
2. as you're pushing them into the vector, keep a running sum
3. calculate the average using this sum and the size of the vector
4. for each value in your vector take the average from this and square this (i'd store these values in another vector for debugging purposes.
5. Calculate the average of these values and take the square root of this.
Seems like you are try to doing this , but you don't need 2 while loops over the file.