Input of numerical data from a file

I am currently writing a program to statistically test data I have done
                         the main body of the program but am having trouble setting up an
                         input so that I can just read from any disk full of numerical data into a
                         Ideally all the data I have will come as doubles seperated in the file by
                         a blank space in between each reading I need the program to take
                         them 51 at a time and place them in a vector so that the stats test
                         can be carried out upon them.
                         I am fairly certain I need to use an IFStream command but am unsure
                         as to how exactly to get precisely the outcome I want.
                         Any advice will be gladly accepted
Who is Participating?
nietodConnect With a Mentor Commented:
MFC isn't relevant for this nor is atof(), this is standard C++.

vector<double> Vec;
fstream Fil("yourfilepath",ios::in);
int Count = 0;


while (!Fil.eof()) //While not at end of file.
    Fil >> Vec[Count++];  // read the number
    if (Count >= 50)  // If 51 values read, then
         // process the data
        Count = 0; // Start over.

// check here if count is not 0.  if not 0, then your data wasn't a multiple of 51 items.

Let me know if you have any questions.
Do you want to know how to read from the file or process the numbers after you have read the from file?

Are you using MFC? ( Makes things easier )

to convert strings to a float or double value you can use the function

double atof( const char *string );

Gunnar Valur

All Courses

From novice to tech pro — start learning today.