i'm reading file which has some number of columns each line has different number of columns and they are numerical values of different length, and i have fix number of rows (20) how to put each column in to array?
suppose i have data file like following (there is tab between each column)
how to put these columns into different array,, that column 1 goes to one arrary and column 2 goes to another. Only column 2 has more than 2 digit values and the rest of columns has 1 or two digit values, and some columns are null too except 1, 2, and 3
#include <vector>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
int main() {
std::vector<std::vector<int> > allData;
std::ifstream fin("data.dat");
std::string line;
while (std::getline(fin, line)) { // for each line
std::vector<int> lineData; // create a new row
int val;
std::istringstream lineStream(line);
while (lineStream >> val) { // for each value in line
lineData.push_back(val); // add to the current row
}
allData.push_back(lineData); // add row to allData
}
//std::cout << "row 0 contains " << allData[0].size() << " columns\n";
//std::cout << "row 0, column 1 is " << allData[0][1] << '\n';
}
now the problem is that my array is filled with garbage values, where i don't have a value in file?