I am trying to create a program that reads a text file into an array of strings. I do have to use pointers since the size of the array is determined first by reading the text file (first line of file is size or array).
The code as it is is not compiling. The list of errors is long and includes things like "no match for operator >>" in reference to inFile >> rows.
I realize there are other ways to create an array of strings, but since this is for a class I need to continue to use the for loop.
#include <iostream>
#include <string>
#include <fstream>
int main()
{
std::string** arr = nullptr;
int rows = 0;
std::string myFile = "data.txt";
std::ifstream inFile;
inFile.open(myFile);
inFile >> rows; \\first line of txt file is number of rows
for (int i = 0; i < rows; i ++)
{
inFile >> arr[i];
std::cout<<"\n"<<arr[i];
}
for (int i = 0; i < rows; i++)
{
delete[] arr[i];
}
delete[] arr;
inFile.close();
return(0);
}