using "scientific" and positive and negative numbers

Hi everyone!

I am generating some contend for a file which should look like:

1
2
3
4
N, 1, -1.2244281e-16,  9.9985440e-01,  6.5286169e-03
N, 2, -5.9098613e-01,  5.7123756e-01, -5.6865174e-01
N, 3,  5.8454788e-01,  5.7182080e-01,  5.7482868e-01
N, 4,  0.0000000e+00,  3.9354077e-08, -1.0000000e+00


(Note the different spacing for positive and negative numbers.)

Right now I am doing the following:
1
2
3
4
5
6
7
8
9
10
11
for(int i=0; i<n; i++)
{
 file.precision(7);
  if(z<0){
   file<<std::scientific<<z<<std::endl;
  }
 else{
  file<<" "<<std::scientific<<z<<std::endl;
 }
 //do more stuff
}


This works but I would like to use a more straight forward approach using "width" or something similar. A first search yielded nothing. Any ideas?
Last edited on
what about std::showpos or std::setw and std::right ?
Last edited on
Topic archived. No new replies allowed.