Hello, I'm almost done with my program however I'm having trouble getting what I want printed to a file. I'm familiar with the printf function and what I want is to print out to the file in scientific notation, which would be %E if I were using printf. Is there something similar when writing out to a file. Also when using printf you can choose how many decimal places you need using %.2f or something like that, I also need to use something similar to that when writing out to a file. Here is how I have been writing out to a file. Can someone please help.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <fstream>
#define MINMASS (0.0000515053396)
#define pi (3.14159265)
#define JUPVOL (6.98509E9 * 6.98509E9 * 6.98509E9 * (4.00/3.00) * pi)
#define SOLM2G (1.98892E33)
using namespace std;
int main ()
{
double j1, j2, j3, j4;
ofstream file;
file.open("big.in"); //open a file
srand ( time(NULL) );
srand48(time(NULL));
j1 = drand48() * 0.013365; //mass needs to be between 5.15053396E-5 and 0.013365
while(j1 < MINMASS)
{
srand48(time(NULL));
j1 = drand48() * 0.013365;
}
file<<" JOVIAN1 m="<<j1<<" r=20.D0 d="<<(j1/JUPVOL)*SOLM2G ;
file.close(); //close it
return 0;
}