Question: C++ Help. Dynamic 2D arrays. Pointers. I'm supposed to input strings from a file into a 2D array of type characters. So far I have
C++ Help. Dynamic 2D arrays. Pointers.
I'm supposed to input strings from a file into a 2D array of type characters. So far I have this for the 2D array:

lineCounter counts how many lines are in the file and determines how big the 2D pointer array should be.
From here I'm trying to store each string line into the pointer array:

I've tried arr[i] = line, but that doesn't seem to work.
How would I make this happen, and for further help, how would I access these arrays of char from the array to compare them? I will have to compare then later on.
Here is my code. Any help would be appreciated:
int main() { string line; int lineCounter = 0; ifstream inputFile("input1.txt"); while (inputFile.is_open()) { while (getline(inputFile, line)) { lineCounter++; } inputFile.close(); }
char** arr =new char*[lineCounter]; for (int i = 0; i
ifstream inputFile("input1.txt"); while (inputFile.is_open()) { for (int i = 0; i
system("pause"); }
int main() string line; int lineCounter-e ifstream inputFile("input1.txt"); while (inputFile.is_open()) while (getline(inputFile, line)) [ lineCounter++; inputFile.close(); char* arr -new char*[lineCounter]: for (inti -e; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
