I am trying to read in a text file of characters including blank spaces. I've tried a few solutions but all of different problems.
The input file looks like this:
1 2 3 4 5 6
0000000
0
00 00 0
0 00000
0000000
0000000
(this text file input isn't formatting correctly, but I hope you get the idea- it's correct in my program)
1 2 3 4 5 6 7 8 9 10 11 12
char** arr = newchar*[rows];
for (int i = 0; i < rows; i ++)
{
arr[i] = newchar[columns];
for (int j = 0; j < columns; j++)
{
std::getline(inFile,line);
temp = line[j];
arr[i][j] = temp;
}
std::cout<<"\n";
}
This code displays the correct number of rows but every character appears as a 0.
1 2 3 4 5 6 7 8 9 10 11
char** arr = newchar*[rows];
for (int i = 0; i < rows; i ++)
{
arr[i] = newchar[columns];
for (int j = 0; j < columns; j++)
{
inFile.get(temp);
arr[i][j] = temp;
}
std::cout<<"\n";
}
This is the closest I have this to working, it displays correctly but the newline char is included in the file so there appears to be an extra blank line between each row.
1 2 3 4 5 6 7 8 9 10 11 12 13
char** arr = newchar*[rows];
for (int i = 0; i < rows; i ++)
{
arr[i] = newchar[columns];
for (int j = 0; j < columns; j++)
{
inFile.get(temp);
std::cin.ignore(temp, '\n');
arr[i][j] = temp;
}
std::cout<<"\n";
}
Whenever I do getline it reads in the first 3 lines as one line. Is there a way to fix this? I've tried rewriting the file a few times, but still encounter the same problem.