|
-
Jun 18th, 2002, 10:11 PM
#1
Thread Starter
Addicted Member
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/>
-
Jul 2nd, 2002, 04:42 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|