I have an text file with binary values in n columns and y rows.
I am using getline to extract every row of the binary values and assign them to vectors:
I am using getline to extract every row of a file, where each row consists of a series of '0' or '1' separated by space, and assign them to a vector.
std::vector< std::vector<int> > matrix; // to hold everything.
std::string line;
while(std::getline(file,line))
{
std::stringstream linestream(line);
int a,b,c,d;
linestream >> a >> sep >> b >> sep >> c >> sep >> d;
std::vector <int> vi;
vi.push_back(a);
vi.push_back(b);
vi.push_back(c);
vi.push_back(d);
matrix.push_back(vi);
}
Now the problem is that I do not know in advance how many columns are there in the file. How can I loop through every line until i reach the end of that line?