I've been messing with this for a few hours and I just can't seem to get what I want. I've been over the documents on this for a while and I can't see what I need.
What I want: I've got a text file that has data in it(20x15): and I want to read in the data (as an integer). However, the data is read in as ASCII and my 0's are 48's, 1's are 49's and the 2 is 50.
001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001
001 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
001 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
001 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
001 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
001 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
001 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
001 000 000 000 000 000 000 000 000 000 002 000 000 000 000 000 000 000 000 000
001 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
001 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
001 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
001 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
001 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
001 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001
Here is my code that I'm working with.
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main(){
int worldX=20;
int worldY=15;
int tileID[20][15];
ifstream mapInput("worldmapsmall.txt");
for(int y=0; y<worldY; y++){
for(int x=0; x<worldX; x++){
tileID[x][y] = mapInput.get();
//if there is a new line character (ASCII value 10) get the next
//digit and place it in tileID[x][y]
if (tileID[x][y] == 10) {
tileID[x][y] = mapInput.get();
cout << endl;
cout << tileID[x][y];
}
else{
cout << tileID[x][y];
}
}
}
mapInput.close();
}
What do I need to do to pull each block of 3 and store that set as 1 integer in the location tileID[x][y]?
The set of data that the above works with looks like this:
11111111111111111111
10000000000000000001
10000000000000000001
10000000000000000001
10000000000000000001
10000000000000000001
10000000020000000001
10000000000000000001
10000000000000000001
10000000000000000001
10000000000000000001
10000000000000000001
10000000000000000001
10000000000000000001
11111111111111111111