Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. void readMatrix(float **&matrix, int &n) {
  2.     //odczytywanie z pliku
  3.     ifstream file;
  4.     string filename;
  5.     cin >> filename;
  6.     file.open(filename);
  7.     if (file.good()) {
  8.         string row;
  9.         bool row1 = false;
  10.         int i = 0;
  11.         while (getline(file, row)) {
  12.             if (!row1) {
  13.                 row1 = true;
  14.                 int amount = count(row.begin(), row.end(), ';');
  15.                 if (matrix != NULL)
  16.                     deleteMatrix(matrix, n);
  17.                 makeMatrix(matrix, amount);
  18.                 n = amount;
  19.             }
  20.             istringstream columns(row);
  21.             string column;
  22.             int j = 0;
  23.             while (getline(columns, column, ';')) {
  24.                 matrix[i][j] = atof(column.c_str());
  25.                 j++;
  26.             }
  27.             i++;
  28.         }
  29.         file.close();
  30.     }
  31.     else cout << "Nie ma dostępu do pliku." << endl;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement