Advertisement
dxvmxnd

Untitled

Oct 24th, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. string path;
  9. bool isIncorrect;
  10. int** matrix = nullptr;
  11. int size = 0;
  12.  
  13. do {
  14. isIncorrect = false;
  15. cout << "Enter the file path: ";
  16. getline(cin, path);
  17.  
  18. ofstream fout(path);
  19. if (fout.is_open()) {
  20. fin >> size;
  21. matrix = new int* [size];
  22. for (int i = 0; i < size; i++) {
  23. matrix[i] = new int[size];
  24. for (int j = 0; j < size; j++) {
  25. fin >> matrix[i][j];
  26. }
  27. }
  28. fout.close();
  29. }
  30. else {
  31. cout << "Error opening file" << endl;
  32. isIncorrect = true;
  33. }
  34.  
  35. } while (isIncorrect);
  36.  
  37. for (int i = 0; i < size; i++) {
  38. for (int j = 0; j < size; j++) {
  39. cout << matrix[i][j] << " ";
  40. }
  41. cout << endl;
  42. }
  43.  
  44. for (int i = 0; i < size; i++) {
  45. delete[] matrix[i];
  46. }
  47. delete[] matrix;
  48.  
  49. return 0;
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement