I have to make a labyrinth game using text. I input the file containing the map from an input file and put it in a 2d array but when i try to display it something goes wrong. While inputting the text the spaces r skipped so instead of this:
xxx xxxxxx xxxxxxxxx
xxx xxxxxx xxxxxxxxx
xxx xxxxxx i get this xxxxxxxxx
xxx xxxxxx xxxxxxxxx
xxx xxx
xxxxxxxxxx xxxxxxxxxx
i used .peek to check for spaces but since it keeps checking the same spot without advancing it creates an infinite loop.
If i try to read after using data peek and i find a space it skips all spaces until it finds an x. So what can i do to keep the spaces from the input file.
I'm not sure what .peek is but i know that the getline() function reads a full line including spaces. You'd have to use fstream.h and use an ifstream object. Something like this:
1 2 3 4
ifstream in("filename.txt") // The file to read in the text from
char buffer[30]; // Somewhere to store the text read
in.getline(buffer, sizeof buffer, '\n');