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
                         vector.
                         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
JHannahAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gvgCommented:
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



0
nietodCommented:
MFC isn't relevant for this nor is atof(), this is standard C++.

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

Vec.resize(51);

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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.