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)
{
dosomething();
closefiles();
cout << "error in data file\n";
exit(1);
}
. . .
// 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.

->HS




--
To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx with a subject of "unsubscribe". Trouble? Contact listmaster@xxxxxxxxxxxxxxxx



Relevant Pages

  • Re: [OT] C++ programming: keeping count of data items read from file
    ... HTH ... Kind of defeats the purpose of having string in the first place.) ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx with a subject of "unsubscribe". ...
    (Debian-User)
  • Re: OT: matched string of a regular expression
    ... However my sed script currently involves 6 lines (for all the ... how can I obtain the string that is matched by a regular ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ... Trouble? ...
    (Debian-User)
  • Re: OT: matched string of a regular expression
    ... However my sed script currently involves 6 lines (for all the ... is the string matched by the first regular ... how can I obtain the string that is matched by a regular ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)
  • Re[2]: ppp -auto my_provider
    ... full log (if it help you remeber that string, ... typing killall sendmail ... To unsubscribe, ...
    (freebsd-questions)
  • Re: bash expansion crap...
    ... Brace expansion is performed before any other expansions, ... I added a sample sanity check. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)