[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: C++ programming: keeping count of data items read from file

Mark Allums wrote:

Not directly helpful, but some suggestions:

1. You might want to learn PERL or Python or Ruby, and do it there.

hmm .. not sure how this will pan out in the long run, but for now, I am trying to keep it all within one program.

2. If it has to be C++, learn enough PERL to write a filter for the data file, and transform it so that it has one double per line. 3. Debug the data generator /in situ/ with a good debugger, and bypass the need to do the sanity checking.

Totally agree with this. The sanity checking was mainly for the data files when some other user may use at a later date.

4. Find a good C++ reference, and use it.  There are several.

Slightly more helpful:

1. Read one line at a time in as a string, then operate on the string.
2. C++ has the ability to do everything that C does in a low level way, but why? Use the C++ way, or use the C way:

#include <cstdio>
#include <iostream>
. . .
using namespace std;
. . .
ios::sync_with stdio();
. . .
int blah = fscanf(somefile,"%f %f %f %f\n", d1,d2,d3,d4);
if (blah != correctvalue)
    cout << "error in data file\n";
. . .
// etc.

(The ios::sync_with_stdio(); line may differ slightly on different C++ implementations. I haven't used it in a while. May be spelled synch_. Too lazy to look it up.

The fscanf line may just be wrong. I quit writing C programs years ago. Too old, memory failing.)

Yup, that fscanf method looks interesting. I used that only when I program in C, but it might be judicious to use it in C++ in this situation.

Never mind the syntax accuracy, I can fix that if need be. Looks like I may need to give this approach shot. Thanks.


Reply to: