Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int main() {
  8.     const char* filename = "matrix.backup";
  9.  
  10.     int row = 3, col = 3;
  11.     int* matrix = new int [row*col];
  12.  
  13.     for(int i = 0; i < row; ++i) {
  14.     for(int j = 0; j < col; ++j) {
  15.         matrix[i*col + j] = i*col + j;
  16.     }
  17.     }
  18.  
  19.     ofstream output_file_stream;
  20.     output_file_stream.open(filename);
  21.     for(int i = 0; i < row; ++i) {
  22.     for(int j = 0; j < col; ++j) {
  23.         output_file_stream << matrix[i*col + j] << " ";
  24.     }
  25.  
  26.     output_file_stream << endl;
  27.     }
  28.  
  29.     delete [] matrix;
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement