Hi all, I'm new to c++ and currently i need to write a program to open csv file and store all data into a vector of double. After trying my codes for few days, i have encountered a problem. I couldn't load all columns of csv data into an array.Please help me to check my codes where is the problem.
My main function codes:
while (getline(inFile, line))
{
double item[3];
int nearestID = CSOINN::NOT_FOUND;
istringstream lineStream(line);
for(j = 0; j < 3; j++){
lineStream >> item[j];
cout << "item: " <<item[j] <<endl;
signal = &item[j];
}
pSOINN->InputSignal(signal);
}
cout << endl;
cout << "Input finished processing, classifying..." <<" " <<endl;
pSOINN->Classify();
system("PAUSE");
return 0;
}
Then "signal" should contain all the data from csv.file's column and pass data to InputSignal function.
bool CSOINN::InputSignal(const double *signal){
FindWinnerAndSecondWinner(winner, secondWinner, signal);
}
bool CSOINN::FindWinnerAndSecondWinner(int &winner, int &secondWinner, const double *signal){
dist = Distance(m_nodeInfo[i].m_signal, signal);
}
double CSOINN::Distance(const double *signal1, const double *signal2)
{
int i;
double sum;
double error;
if (signal1 == NULL || signal2 == NULL) return 0.0;
error = 0.0;
sum = 0.0;
for (i=0; i<m_dimension; i++)
{
sum += (signal1[i]-signal2[i])*(signal1[i]-signal2[i]);
}
return sqrt(sum)/(double)m_dimension;
}
How can i use a pointer to store all data from the csv.file's column and pass to these functions?hope you can help me out. I have been stuck for few days ago..
My CSV file data sample as below:
1223134360 13016 722 809 0.008 0 -0.002
1223134360 13017 612 723 0.012 0 -0.003
1223134360 13018 590 627 0.015 0 -0.004
1223134360 13019 609 600 0.018 0 -0.003
1223134360 13020 607 629 0.022 0 -0.004
1223134360 13021 629 624 0.025 0 -0.004
1223134360 13022 666 629 0.029 0 -0.003
And I'm expect each time my pointer should store for example:
1223134 13016 722 809 0.008 0 -0.002
Unfortunately, my program output is like this:
1223134360 2.54183e-317 8.2609e-318 and so on..
Hope you guys can help me out.Thanks.