0

This function is supposed to open a file stream and copy the text into an integer array to be used for a map key. Here is the contents of the file. I am getting the decimal value stored in the array and I just cannot figure out how to correct the problem. I tried casting, atoi(), and other stuff, but I am still not figuring it out.

0000000000000000
0111110000000000
0111110222220000
0111111222220000
0111110222220000
0111110222220000
0000010222220000
0000030020000000
0000333330000000
0000333330000050
0000333330444440
0000333333444440
0000333330444440
0000000000444440
0000000000444440
0000000000000000

void map::initMapKey()
{
	j_mapFile.open( jMapName, std::ios_base::in);		// open the file for storing
	j_mapFile.flags( std::ios_base::dec);

	if(!j_mapFile.is_open() )
	{
		cout << "File could not be opened!";
	}
	else{

		for(int i=0;i<jMaxRows;i++)					// loop for each row
		{
			for(int j=0;j<jMaxCols;j++)
			{	
				int myInt = j_mapFile.get();
				j_mapKey[i][j] = myInt;
			}
					
		
		}
	}
	j_mapFile.close();
}
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by WaltP
0

You're reading into an integer and each line contains an integer. Even though you didn't explain what you actually want I assume you mean to read each individual digit into the j_mapKey array. If so, read each digit as a char and convert to an integer by subtracting 48.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.