I am a college student and as part of my final project for a c++ class we are assigned to read a csv file that has distance and force data and then find torque from it. The problem that I am running into is how to actually get the data out of the csv file into a workable format. Currently I have been trying to get it into a matrix, to do this though I will need to first determine the size of the csv file as it is supposed to take any size file. This is the format of the data
Case 1,,,,,x_position (m),y_position (m),z_position (m),F_x (N),F_y (N),F_z (N)16.00,5.00,8.00,394.00,-18.00,396.0022.00,26.00,14.00,-324.00,-420.00,429.0028.00,25.00,21.00,73.00,-396.00,-401.006.00,9.00,12.00,-367.00,-137.00,-143.00
Also obviously the different data pieces (distance and forces) need to be put into different vectors or matrices. This is what I have so far to try to find the number of lines in the file.
ifstream myfile("force_measurements.csv");
if(myfile.is_open()){
string line;
double num=0;
getline(myfile, line);
if(line==""){
cout<<num<<endl;
myfile.close();
}
else{
num++;
}
}
After this works how would you go about putting the data into a matrix? or would a different format be easier? vectors was my other though.