I have an example code for reading a file and working with the values in c++ but I don't understand how it works:
Code:
#include <iostream>
#include<fstream>
using namespace std;
class v3d{
double x,y,z;
public:
v3d(double a=0,double b=0,double c=0){x=a; y=b; z=c;}
void operator+=(v3d a);
friend ostream& operator<<(ostream& out, const v3d &s);
friend v3d operator*(double a, v3d b);
};
v3d operator*(double a, v3d b){
return v3d(a*b.x,a*b.y,a*b.z);
}
void v3d::operator+=(v3d a){
x+=a.x;y+=a.y;z+=a.z;
}
ostream& operator<<(ostream& out, const v3d &s)
{
out << s.x << " " << s.y << " " << s.z;
return out;
}
int main(void){
int i;
v3d s(0,0), v(2,2), F(0,-10);
double dt=1e-2,m=1.;
for (i=0;i<40;i++){
v+=1./m*dt*F;
s+=dt*v;
cout << i*dt << " " << s << " " << v << endl;
}
}
This programm reads a file called "move.dat". I don't understand how this works. There is not even the name of the file and still it works. Can somebody pleas explain me where and how the reading is done?