I wanted to make a C++ code where, a txt file has a number in the beginning with the amount of rows in the column, and then there would be data in the bottom that a dynamic 2d array will take. The thing is, I wanted to make a jagged array, but not specify the exact length for each row. So far, I've got the rest of the code done, but I can't figure out this part of the logic. Help would be greatly appreciated.
#include <iostream>
#include <fstream>
usingnamespace std;
void Readfile(int**, ifstream&);
int main()
{
int** Matrix = {};
int Rows = {};
char FileName[100];
ifstream Main;
cout << "Enter File Name here: ";
cin >> FileName; // This will allow a user to enter their own txt file for input
for (int i = 0; i < 100; i++)
{
if (FileName[i] == -52 || FileName[i] == '\0')
{
for (int j = i; j < (i + 4); j++)
{
if (j == i)
{
FileName[j] = '.';
}
elseif (j == i + 1 || j == i + 3)
{
FileName[j] = 't';
if (j == i + 3)
{
FileName[j + 1] = '\0';
}
}
elseif (j == i + 2)
{
FileName[j] = 'x';
}
}
break;
}
}
Main.open(FileName);
if (Main.is_open())
{
cout << "This file exists!" << endl;
cout << endl;
Readfile(Matrix, Main);
}
elseif (!Main.is_open())
{
cout << "This file does not exist." << endl;
}
}
void Readfile(int** Matrix, ifstream& Main) // Function for reading data from the txt file
{
int Rows;
Matrix = newint*[];
Main >> Rows;
int *Column = newint[Rows];
for (int i = 0; i < Rows; i++)
{
Matrix[i] = newint[Column[]]; // With an input 'i' this would be Matrix[i] = new int[Column[i]];
// because the columns will be decided by the txt file the 'i' for Column[] is omitted.
for (int j = 0; j < Column[i]; j++)
{
Main >> Matrix[i][j];
}
}
}