Need help writing data to a file

I have a commercial gyro sensor that I'm trying to get data off of. By the sample code, I've been able to get the data to display in the window as it outputs it, but I'd like to save the data to a file. The data I want saved are:

1. The time stamp
2. The X gyro data
3. The Y gyro data
4. The Z gyro data
The code I'm using is a while statement as follows;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
  while(1)
  {
     //Checks, if sensor is connected
     if (lpms ->getConnectionStatus() == SENSOR_CONNECTION_CONNECTED &&
         lpms->hasImuData())
     {
       // Reads Gyro data
       d = lpms->geturrentData();
       
       // Shows data
       printf("Timestamp=%f, gX=%f, gY=%f, gZ=%f\n",
           d.timeStamp, d.g[0], d.g[1], d,g[2]);
      }
      


I sure the data that gets printed out is from the printf(), so what I would assume is that the printf() statement would be replaced by a ofstream but I've been unsuccessful. If this is not enough code I can fix that.

Thanks -
Since you seem to be using C have you considered using fprintf()?

you can also run what you have from the commandline with a direct output to file command.
programname > filename
Thanks for the suggestions!
Topic archived. No new replies allowed.