Hi guys, I pretty new to c++ and I have a problem with getline. I am supposed to call in a text file into a 2d character array and the text file is a maze. Here is my code:

void maze::open()
{
	ifstream file;
	int row=0;
	file.open("standard.txt");
	while (!file.eof())
	{
		getline(file, store);

		for ( int col = 0 ; col < store.size() ; col++ )
		{
			Maze[row][col] = store[col];//store is a string variable
		}
		row++;
	}
	file.close();
}
void maze::printmaze()
{
	for(int i=0;i<50;i++)
	{
		for(int j=0;j<20;j++)
		{
			cout<<Maze[i][j];
		}

	}
	cout<<endl;
}

I have been getting weird outputs and I tried searching through this forum for similiar problems but i didn't find any. Please help me.

Do you use the >> or any other input method in the program? Whenever you use more than one input method in a program you need to be aware of the status of the input buffer before each input.

It looks like you attempted to input the maze line by line, but you output the maze char by char. Was that intended?

To start a new line of char in the output section teh call to endl should be placed after the inner loop completes each sequence, not after the outer loop completes it's sequence.

Hey guys I have solved the problem. It lies it the printing out of the maze. Thanks for the help anyways and also about the problems with file.eof.

This question has already been answered. Start a new discussion instead.