Reading in an array of text from a file?
Well, I've got single lines down, so I'm not a total failure here. However, I'm trying to read a 10x10 array of characters from a textfile into a 10x10 array of characters in a... char map[10][10].
Someone suggested using getline, 10 times, in a loop.
Code:
int main()
{
ifstream mapFile;
mapFile.open("map/map01.txt");
mapFile.getline(&map[0][0],10);
mapFile.close();
cout << map[1][1];
int hi;
cin >> hi;
return 0;
}
So, when the 10xtimes in a loop thing failed, I took the loop bit out and just tried reading in the first line of text.
Now, my understanding of the syntax is this: getline reads from mapFile, and puts the text into map, starting at *map[0][0], and reads in for... 10 characters in the text file. From my understanding, this should put the first line of the text file into positions [0][0] to [10][0] in char map.
Obviously my understanding is wrong, because I'm making this post. More specifically, I get blank output from cout << map[1][1]. Which, from my understanding, should display the character in the array at position [1][1]. I tested this by include map[1][1] = 'a' right above the cout bit.
Er, yes, so I guess I'm wondering what I need to plug into getline to... get it properly reading my lines, or if that's the entirely wrong approach.