c++ - Matrix - reading from file -
I have a problem using the function to read metrics from the file ...
My class looks like this:
contains #lt; Iostream & gt; #to & lt include, cmath & gt; #include & lt; string & gt; #to & lt include, fstream & gt; using namespace std; Class matrix {public: matrix (int, int); Matrix (Const Metrics and Copy Matrix); ~ Matrix (); Matrix (cons four * sczaka); In the Matrix & amp; Wypelnij (string); Dost Ostream & amp; For operator & lt; & Lt; (Ostream End, Matrix & amp;); In the Matrix & amp; Operator + = (Const Metrix & amp;;); In the Matrix & amp; Operator- = (cost matrix & amp; amp; md;); In the Matrix & amp; Operator * = (Const Metrix & amp;;); In the Matrix & amp; Operator = (Const Metrix & amp;;); Buddy Matrix Operator * (Const Metrics and Left, Const Metrics and Right); Buddy Matrix Operator + (Const Metrics and Left, Constant Matrix and Right); Buddy Matrix Operator- (Cost Matrix and Left, Constant Matrix and Write); Class alokairr {}; Class OpenError {}; Class incorrect size {}; Private: Double ** Massierz; Unsigned intestinal wounds; }; Constructor: Matrix :: Matrix (int x = 1, int y = 1): Wise (x), colmini (y) {if (Wires and lt; 1 || columny & lt; 1) {For Alok Err (;); } Maseraz = new double * [wires]; For (unsigned i = 0; i
And finally the function
matrix :: matrix (constrate * sijaka) {ifstream plik (sciezka); if (plik.good ()! = True) {openError (); unsigned , K; plik>> w> gt; if (w <1 || k & lt; 1) AllocError (); double ** tap = new double * [w]; Double * Pmc = new double for [w * k]; for (unsigned i = 0; i & lt; w; i ++) {temp [i] = pmx + (i * k);} (unsigned i = 0; i & lt; w; i ++) {for (unsigned Jammu = 0; j & lt; k; j ++) {plik> [i] [ja];}} Wiersze = w; kolumny = k; macierz = floating; // for (unsigned I = 0; i & lt; w; i ++) // IT work also also // {// massier [i] = floating [i]; //} (unsigned i = 0; i
This works hard when I do not use removal at the end of fun, when I do, some numbers are wrong if matrix A ("text.txt") Fill the matrix B (5,5). B ("B") Crashes after completing all calculations, such as matrix C (5,5) C = A + B ...
@edit
I've only done this to change the end of the F:
wiersze = w; Kolumny = k; // macierz = temporary; Massierz = New Double * [W]; (Unsigned i = 0; i & lt; w; i ++) {Masirs [i] = for new double [k]; For (unsigned j = 0; j; l; k; j ++) {masiraj [i] [j] = temporary [i] [j]; }} Plik.close (); Delete [] * temp; Delete [] temp; }
Any easy way to read from the file? I do not really like this code
To remove the matrix, you must follow the reverse order of allocation Should do:
for (unsigned i = 0; i
Comments
Post a Comment