Problem with iterators and maps

So i'm trying to read in some x/y. co-ordinates from a txt file and than assign them to enemies so that i can later use this function in a factory method.

i've gotten the program to read the co-ords in from the file and put them into a map with the x co-ord as key and the y co-ord as value but i can't seem to find a way to iterate through the map to than assign the values to my enemies.

I keep getting an error with the iterator not allowing me to assign it to the beginning of the spawn map.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

//code that calls the function
for (int i = 0; i <= 10; i++)
	{
		obstacle[i]->Spawn(obstacle[i], functionCounter);
		functionCounter++;
	}

//Function that assigns spawn co-ords to enemies
void Obstacle::Spawn(Obstacle* obstacle, int spawnCounter)
{
	fstream sFile;
	map<char, int> ::iterator it;
	int x, y;
	int counter = 0;

	map<int,int> spawn;
	sFile.open("obstacleSpawn.txt", fstream::out);
	while (sFile >> x >> y)
	{
		spawn[x] = y;
	}
	for (it = spawn.begin(); it != spawn.end(); it++)
	{
		if (counter == spawnCounter)
		{
			obstacle->set_world_position(x, y);
		}
		else
		{
			counter++;
		}
	}
}


errors i am getting are:
1 IntelliSense: no operator "=" matches these operands
operand types are: std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const char, int>>>> = std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const int, int>>>>

2 IntelliSense: no operator "!=" matches these operands
operand types are: std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const char, int>>>> != std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const int, int>>>>
Spot the difference:
1
2
map<char, int> ::iterator it;
map<int,int> spawn;
god feel so dumb its always something so small with my programs :(
thank you.

although now only 4/9 of my enemies are spawning now.
god feel so dumb its always something so small with my programs

Don't feel bad. This is such a common problem that they added (changed actually) auto to the standard. You could delete line 13 altogether and change line 23 to:
for (auto it = spawn.begin(); it != spawn.end(); it++)
Topic archived. No new replies allowed.