So as the title says I'm trying to read from a file and save the characters into a 2d array with spaces but it gets stuck in the do while loop and last char of the file. any suggestions on how to fix this? i thought about using the eofbit but I couldn't figure it out then i tried exiting the do while loop by || it with eof that didnt work. it seems to just hang on the last letter of the file. thank you in advance for your advice
char ch[100][100];
int row_count =0;
int col_count = 0;
int col[100];
char temp; 
bool exit = false;
ifstream infile("data.txt");
if( infile.is_open())
{
    while(!infile.eof())
    {
        do
        {
            infile.get(temp);
            char[row_count][col_count] = temp;
            col_count++;
        }while(temp != '\n' || !infile.eof());
        col[row_count] = col_count;
        row_count++;
        col_count= 0;
    }
}
for(int i = 0; i <= 2; i++)
{
    for(int j=0; i <= col[i]; j++)
    {
        cout << ch[i][j];
    }
    cout << endl;
}
return 0;
}
 
     
     
     
    