Find the size of row and column using vector c++

I am very new to c++ and doing Gaussian Elimination.I am not sure how to determine the size of vector. That's read the number of row and column from a file that contains unknown row and column. I don't know why my number of row is 13. For Instance, the file was given: 1 1 1 3 2 3 7 0 1 3 -2 17

#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int main()
{

vector<vector<double>> matrix;;  // matrix vector is a vector of vectors
vector<double> row;  //a row of the vector is actually a single vector
string filename;
ifstream inFile;
cout << "Enter Matrix File:";
cin >> filename;
//open the input file
inFile.open(filename);
//if input file cannot be opened or is missing show error and exit
if (!inFile)
{
    cout << "Error opening the input file: " + filename << endl;
    exit(2);
}
while (inFile)
{
    string line;   
    getline(inFile, line);
    if (line.empty()) 
        break;   
    // Do things with the line   
    cout << "[\t" << line << "\t\t]" << endl;
}
cout << "Num rows:" << filename.size() << endl;
cout << "Num cols:" << filename[0].size() << endl;
inFile.close();
return 0;
}
vector<double> ReadRow(string line) 
{ 
    stringstream ss(line); 
    vector<double> row   
    double val;   
    while (ss >> val) 
    { 
        row.push_back(val);
    }   
    return row;
}


from Recent Questions - Stack Overflow https://ift.tt/34vF0tu
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)