I need to read in a text file that contains only integers and each one is separated by new line. example would be:
0
1
2
...
64
repeating 0 to 64 64 times
Essentially the file is 64*64 lines long, containing an integer for each line.
I need to store each integer (line) in ldisk, my 2D array, but am having serious problems doing so. I understand my code has an error because I am trying to store a string in a char, but I am not sure how to get around this. By the way, ldisk must be a 2-D array of chars. I would love some advice/feedback on my current code posted below, or an alternative solution. NOTE: I am a beginner at C++ PS: I know similar topics exist, but mine is more to the problem of getting around the type conversion or just converting it properly so I can store more than a single digit integer into my 2D array, because I have it working where I can store only the first digit where I want in my 2D array, but run into problems if there is more than 1 digit.
int main(){
char **ldisk;
ldisk = new char*[64];
for (int i = 0; i<64; i++)
{
ldisk[i]= new char[64];
}
int counter = 0;
string line;
ifstream inFile("example2.txt");
while ( getline(inFile, line))
{
int first, second;
first = counter/64;
second = counter%64;
cout << line;
ldisk[first][second]= line;
}
return 0;
}
EDIT: My apologies I have no idea how to do a table.
I want ldisk[0][0] to be 0,
then ldisk[0][1] to be 1,
then ldisk[0][2] to be 2,
etc,
etc,
then ldisk[0][63] to be 64
Eventually it will fill up such that ldisk[63][63] = 64