Range based for on map runs endless

Hi,

I wrote the following code for testing

1
2
3
4
5
6
    std::map<std::string, std::string> test;
    test["realname"] = "abc";
    unsigned int row(0);
    for (auto const &item: test) {
        std::cout << userData.size() << "/" << row << std::endl;
    }

But this loop is never ending. When I compile and run it, the output should be only one line. but after maybe 10000 lines output i stop it.

Does anyone know why?

Greetings torsten

Btw, I'm not able to format (with firefox) this message
Last edited on
It works fine for me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <map>

int main()
{
	struct { int size() { return 0; } } userData;

	std::map<std::string, std::string> test;
	test["realname"] = "abc";
	unsigned int row(0);
	for (auto const &item: test) {
		std::cout << userData.size() << "/" << row << std::endl;
	}
}
0/0


Are you sure the problem is caused by the code that you have posted?
Last edited on
Mhm... I only did copy and paste it from my code, and there I become this error. Only two things are different: The loop runs in a lib and the application is based on a framework that uses boost threads. Maybe one of them is the reason. I'll try it out.
But thanks.
Seems like it was the main application. After I did recomplile that, it works. Thank you.
Topic archived. No new replies allowed.