Help Please

This is my first post, so sorry if I make any mistake. I am trying to create a program that reads text file of a matrix and outputs it in a different file with the sum of rows and columns. I have the code for reading the file but cannot figure out the sum part. Please help

#include <fstream>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>

using namespace std;

int ReadNumbers( const string & s, vector <double> & v );
void import_matrix_from_txt_file(const char* filename_X, vector <double>& v, int& rows, int& cols);


int main(){
vector <double> v;
int rows=0;
int cols=0;

import_matrix_from_txt_file("MatHW1.txt",v,rows,cols);
}

int ReadNumbers( const string & s, vector <double> & v ) {
istringstream is( s );
double n;
while( is >> n ) {
v.push_back( n );
}
return v.size();
}



void import_matrix_from_txt_file(const char* filename_X, vector <double>& v, int& rows, int& cols){

ifstream file_X;
string line;

file_X.open(filename_X);
if (file_X.is_open())
{
int i=0;
getline(file_X, line);


cols =ReadNumbers( line, v );
cout << "cols:" << cols << endl;


for ( i=1;i<100;i++){
if ( getline(file_X, line) == 0 ) break;
ReadNumbers( line, v );

}

rows=i;
cout << "rows :" << rows << endl;
if(rows >100) cout<< "N must be smaller than MAX_INT";

file_X.close();
}
else{
cout << "file open failed";
}

cout << "v:" << endl;
for (int i=0;i<rows;i++){
for (int j=0;j<cols;j++){
cout << v[i*cols+j] << "\t" ;
//cout << v[i]+v[j];
}
cout << endl;
}


}
A few things.
Choose a more descriptive title - maybe sth. like "Problem finding sum in a matrix"
Put your code in code-tags: http://www.cplusplus.com/forum/articles/42672/
Show us the input file you use
Topic archived. No new replies allowed.