So I'm having a little bit of trouble reading from a text file in C++. What I'm trying to do is read from a text file that contains a grid of letters. Here's what I have set up:
int main()
{
char grid[10][10];
ifstream input;
input.open("puzzle1_size10.txt");
//what goes here
input.close();
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
cout<< grid[i][j]<<" ";
cout<<endl;
}
}
The text file is this:
10 10
f e h l o a k r a y
e s r r t s c d o y
a l u g d o e e g a
t c y y m h l j y a
u r a p s y n a r j
r e u d c a e p e r
e t s o c h t p h c
e g o p e h w l t w
h h c l s d o e c a
l n h c a m r l e e
The first two numbers represent the size of the grid. I'm trying to read each character (ignoring the initial numbers) and store the character into the array called grid. Any advice?
There are other similar questions I've found on stackoverflow but none have the same context as this and none of them give me a definitive answer. I am simply trying to read one character at a time from a file and store that character into a 2D array so that each letter in the array can be easily referenced. Can someone please help?