how do i read 2 consecutive values in vector and compute?
hey, im new to c++ well actually been working with it for the past two months and i ran into problem.
basically im trying to write a function to read two consecutive values in a vector (they happen to be distances) and calculate the speed at which object is moving and create a new vector with the speeds obtained. im fairly new to C++ and in no way an expert. i can't figure out how to read the first 2 values...do my calculation then output it another vector and repeat.
anyone provide me with any help?
if this helps i wrote this function to read a data file and place objects into a vector. it is THIS vector i need to read to find out the speed of objects. btw Speed[0] = ( Dist[1]-Dist[0] )*(3600/15) is equation for speed if you really want to overachieve
Code:
void readdatafile(vector<double> &Data, string filename)
{
ifstream fin;
fin.open(filename.c_str());
// Open file and error check
if ( fin.fail() ) // open failed
{
cout << "The file could not be opened\n";
}
else
{
char* Firstline = new char[];
fin.getline(Firstline, 20);
double X = 0;
fin >> X;
while( X >= 0)
{
Data.push_back(X);
fin >> X;
}
}
return;
}