Results 1 to 2 of 2

Thread: Reading an indeterminate # of floats into an array

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    183

    Reading an indeterminate # of floats into an array

    I want to read in an indeterminate number of double values from a file into an array, I created the double array with :
    <code>

    #include <Afxtempl.h>
    typedef CArray <double, double> CDoubleArray;

    CStdioFile data;
    CDoubleArray datarray;

    data.Open("datafile2.txt",CFile::modeRead|CFile::shareExclusive);

    <code/>

    Can anyone take it from here? The file looks ".23 .44 .32..."
    here is what I was doing before with a C style IO but I need to use MFC now

    <code>

    #include <Afxtempl.h>
    typedef CArray <double, double> CDoubleArray;

    CDoubleArray datarray;
    CFile * data;
    double tem;
    data = fopen("datafile2.txt","r");

    while(fscanf(data,"%lf",&tem) != EOF)
    dataarray.Add(tem);

    <code/>

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Why are you bound to MFC? The nice thing is that you are never forced to use MFC...
    I can't think of any good way to do the thing you want with MFC, it is not supposed to replace the CRT, but to use it. If you really want to use CFile, read the whole file into a CString and then use sscanf to get the floats. But it is basically a waste of time.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width