Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <sstream>
- using namespace std;
- int main() {
- string path;
- bool isIncorrect;
- int** matrix = nullptr;
- int size = 0;
- do {
- isIncorrect = false;
- cout << "Enter the file path: ";
- getline(cin, path);
- ofstream fout(path);
- if (fout.is_open()) {
- fin >> size;
- matrix = new int* [size];
- for (int i = 0; i < size; i++) {
- matrix[i] = new int[size];
- for (int j = 0; j < size; j++) {
- fin >> matrix[i][j];
- }
- }
- fout.close();
- }
- else {
- cout << "Error opening file" << endl;
- isIncorrect = true;
- }
- } while (isIncorrect);
- for (int i = 0; i < size; i++) {
- for (int j = 0; j < size; j++) {
- cout << matrix[i][j] << " ";
- }
- cout << endl;
- }
- for (int i = 0; i < size; i++) {
- delete[] matrix[i];
- }
- delete[] matrix;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement