I'm working on an app in QT, and I'm kinda new to C++ I/O; I want to read some data from a CSV file that currently has 2 columns and some rows, for example: (1 | 10) (2 | 20) I just want to store them in an array like this (1,10,2,20); for some, only values from the second column get stored in my array. Here is some code; I've checked many times, but I still can't see what I'm doing wrong:
void readingFiles::openFile(){
ofstream myFile;
myFile.open("/home/Dan/Desktop/mainFile.csv" ,std::ios::app);}
void readingFiles::addReadings(int readings1 , int readings2){
if(myFile.is_open()){
myFile<<readings1<<","<<readings2<<"\r";
myFile.close();
}
}
vector<int> values ;
ifstream iFile;
iFile.open("/home/Dan/Desktop/mainFile.csv");}
string data;
void readingFiles::read(){
for(int i =0; std::getline(iFile,data, ',') ; i++){
values.insert(values.end() , atoi(data.c_str()));
qDebug("vector list is %i" , values[i]);}
}
So, the result I get is that it reads the first row in the first column, then moves to read from the second column, and never goes back to the first (1, 10, 20, 30, 40 etc). Again, what I'm trying to get is (1, 10, 2, 20, 3, 30 etc.).