I am using a verlet algorithm in c++ to model the motion of a satellite, and want to output position and velocity data from each timestep so that I can then read it into MATLAB and plot graphs to see how well my model matches the 'real life' graphs. so far I have at the end of each iteration:(adsbygoogle = window.adsbygoogle || []).push({});

Code (Text):

ofstream fout; bool ok;

ok = false;

do{

fout.clear();

fout.open("height_data.dat");

if (fout.good()) ok = true;

}while (!ok);

fout<<height<<endl; //height is the variable with current position to output and store

fout.close();

As far as I have been taught, this should create the file height_data.dat in the same location as the c++program, but it doesn't.

I am also unsure about adding new data at each timestep without erasing previous data, and wondered if it is possible to store time, height and velocity all in one file to use with MATLAB?

Any hints on if and how I can achieve this would be greatly appreciated.

Thanks in advance

:)

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Storing Data From C++ Program to a file.

**Physics Forums | Science Articles, Homework Help, Discussion**