How do I make this code output/debug to a .txt file?

Here is the code:

#include <iostream>
using namespace std;


#define k 100 //force constant= 100 kcal/(mol*A^2)
#define m 16 //mass= 16 Daltons


float x;
float v;
float a; //acceleration
float t; //time
int z;
float dt;

int main ()
{
t=0;
int n;
cout << "Enter the Number of Iterations "<<"\n";
cin >> n;
z=1;
cout<< "Enter Initial Postion:"<<"\n";
cin >> x;
cout<< "Enter Initial Velocity:"<<"\n";
cin >> v;
cout<< "Enter Time Step: "<<"\n";
cin>>dt;
cout<<"t,x"<<"\n";

while (z<n)
{
a= -k*x/m;
x= x + v*dt + .5* a*dt*dt;
v=v+a*dt;
t=t+dt;
cout<<t;
cout<<" , ";
cout<<x<<"\n";
cout<<" ";

z=z+1;
}
system("pause");

return 0;
}