I need to read in a lot (~225k) numbers formatted the following way: 1.2340000000000000D+03. I'd like to read in the number, and re-format it into either scientific notation or general notation (i.e., 123.4). All have the same number of significant figures (I believe this is the FORTRAN double precision convention).
Any ideas of how to do this efficiently? Is there a standard C++ library component that can handle FORTRAN-friendly numbers? I can't read it in just as a double or float because I lose the "D+03" information at the end.
Use string.find() to find 'D' and replace it with 'E'.
Or use std::replace
If you are reading the FORTRAN numbers, from a file, as string then you can:
Replace D with E in file itself prior to reading and then just read them as doubles.
I do not mean to say that your solutions are bad, I merely providing another ways to do that (what to actually should be done depends on many conditions which are unknown to us at this time)
atof() will require the <cstdlib> (Must be included)
.find() will require the <string> (Native, Not necessary with most modern compilers)
stod()/stod() requires <string> (Native, plus requires c++11)
replace() will require <algorithm> (Must be included to use)
Question:
Replace D with E in file itself prior to reading and then just read them as doubles
Can you extend on the method to do so; I am carious, as to what you are introducing. Normally i'd just read the data in, then modify the data. I'm thinking, you've got an automated subroutine, in mind. But brute force is definitely an option; especially with editors widely available.