Hi, I am a mechanical engineer, and I've learnt the basics of VBA (excel's macro) and C++ in the past week, because I have to programm a simple C++ model.
The model has to read some input data from a .csv file (the measurements), elaborate the data and write the results in another .csv file...
The problem I am facing now is that the .csv file is made by 27 variables, measured each second (so it's made by 27 columns and "n" rows, where n is a number between 300 and 800, depending on the lenght of the test). The first row is made by headers, so I want to skip it, and the last column has no coma at the end, but a end-of-line "\n".
I want to assing each of the 27 values read to a variable (double precision), do the calculations, and then go to the next line and do it again until the end of the file...
I am currently using the following code (which is not working correctly):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
char filename[64];
string inputs;
double input_array[26];
cout<<"File to read>";
cin.getline(filename, 64);
ifstream input_data(filename);
if (input_data.is_open())
{
input_data.seekg (1, ios::beg);
while(!input_data.eof())
{
for(int i=0; i<27; i++)
{
getline (input_data, inputs, ',');
Valid_Calculation = 1;
istringstream iss (inputs,istringstream::in);
iss>>input_array[i];
}
//... model calculations
}
}
|
It asks for the name of the file with the scans, opens it and I was trying to use the input_data.seekg command to skip the first line, but it's quite difficult to get the exact number of characters to skip!!!
The for cycle is aimed to store the values read into an array, so that i have separated each variable from the following.
The problem are:
- at the end of each row there isn't a coma, so the getline doesn't separate the last value of a row from the first of the following row.
- I don't know how to skip the first row made by headers (text).
- saving to the array doesn't seem to work, but maybe it's because of the previous problems.
Thank you!