1 Replies - 473 Views - Last Post: 28 March 2009 - 05:25 PM Rate Topic: -----

#1 prolulzibus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 15-August 08

ifstream issues

Posted 28 March 2009 - 04:59 PM

To preface, this is part of a tile engine for a tactical game I'm working on. The data for the map is held in a text file, and the first line of the text file will determine the size of the array the tiles will be stored in. Every subsequent character is a number which corresponds to an image.

When I hard-code the size of the array, and put the ifstream initialization stuff in the for loops, ignoring the first line, it works, but when I move the ifstream outside of the loops, it doesn't.

		std::ifstream text;

		char num;

		text >> num;

				int n = atoi(&num)*10;

		TILE *tilearr[n][n]; //The 2d array of TILEs

		  MAP(int id, int data) {

			char info;
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					text >> info;

					tilearr[i][j] = new TILE(id++, atoi(&info));

Does this have to do with scope, and if so, how can I fix it? Making the ifstream private didn't seem to help.

Is This A Good Question/Topic? 0
  • +

Replies To: ifstream issues

#2 rs4  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 29
  • View blog
  • Posts: 153
  • Joined: 01-February 09

Re: ifstream issues

Posted 28 March 2009 - 05:25 PM

Yes it looks like it is a scope problem, you should be able to fix it by calling classname::text. I don't know why it is a issue for file streams and not other varibles, like int n.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1