Hello,
I am trying to make a script to open many files that differ only at the end. The files are named the same except for the end where it has a value in scientific notation with 5 digits after the decimal. However, the filename uses a capital E whereas c++ likes to use a lowercase e. I have this
nBackground_void_1.00000E-10.m
nBackground_void_9.00000E-9.m
...
and the values at the end are stored in the array out_ergs. right now, the stringstream "filename" is taking the values
Instead of printing the values from 'out_ergs[]' straight into your string stream you could create a second stringstream, print the values from 'out_ergs[]' into this second stream, convert it to a string, iterate through it replacing any lower case e's with upper case e's and then print this to your original string stream.
*Edit: Also you might be interested to know that the printf style functions have the ability to control the capitalization of the 'e' in exponents. See here for more information: http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/
PS If possible, I would code this with the stringstream outside of the loop and then reset it at the start of the loop, to avoid the repeated construction/destruction.
1 2 3 4 5 6 7
ostringstream filename; // using o- version as just for o/p
filename << setprecision(5) << scientific;
for (int i=0; i<80; i++) {
filename.str(""); // clear
filename << "./m/nBackground_void_"
<< uppercase << out_erg[i] << nouppercase << ".m";
...