Computer Science Canada

C++ Iterators, using MinGW

Author:  riveryu [ Sat Mar 21, 2009 7:09 pm ]
Post subject:  C++ Iterators, using MinGW

How do you use iterators?
Code below gave me a strange error.
Windows XP gave me an error and forced me to close it, along with send or not send report.
Thanks in advance.

c:
#include<iostream>
#include<cstdio>
#include<map>
#include<string>

using namespace std;

int main () {
map<string,int> m;
m["a"] = 1;
m["b"] = 1;
m["c"] = 1;
map<string,int>::iterator it;


while (it != m.end()){
cout << (*it).first;
it ++;
}
return 0;
}


How do you do C++ syntax tags...?

Author:  saltpro15 [ Sat Mar 21, 2009 7:18 pm ]
Post subject:  RE:C++ Iterators, using MinGW

which compiler are you using?
and c++ syntax tag is
c++:
Wink

Author:  riveryu [ Sat Mar 21, 2009 7:32 pm ]
Post subject:  RE:C++ Iterators, using MinGW

The title says "...using MinGW", by that i mean i'm using "Minimalist GNU for Windows" compiler.

http://www.mingw.org/ <- their website

I actually sort of doubt its the compiler though. I mean, it atleast did not give warnings or errors when compiling.

I'm using Code::Blocks IDE btw.

Author:  saltpro15 [ Sat Mar 21, 2009 7:34 pm ]
Post subject:  RE:C++ Iterators, using MinGW

Embarassed well that's embarassing lol

well, I'm sorry but I have almost no experience with Code::Blocks, so I'll let someone else field this question

Author:  sharvil [ Sat Mar 21, 2009 10:56 pm ]
Post subject:  Re: C++ Iterators, using MinGW

You forgot to initialize 'it'. The boilerplate that most people use is:

code:
for(std::map <std::string, int>::iterator it = m.begin(); it != m.end(); ++it)
{
    /* Logic */
}

Author:  [Gandalf] [ Sun Mar 22, 2009 12:25 am ]
Post subject:  RE:C++ Iterators, using MinGW

MinGW is the Windows port of the GCC compiler. Smile

Author:  md [ Sun Mar 22, 2009 4:39 pm ]
Post subject:  Re: C++ Iterators, using MinGW

sharvil @ 2009-03-21, 10:56 pm wrote:
You forgot to initialize 'it'. The boilerplate that most people use is:

code:
for(std::map <std::string, int>::iterator it = m.begin(); it != m.end(); ++it)
{
    /* Logic */
}

This exactlt. If you don't initialize your iterator weird thigns happen (if anything... I mostly forget what happens).

Author:  riveryu [ Sun Mar 22, 2009 4:43 pm ]
Post subject:  RE:C++ Iterators, using MinGW

Thanks guys, I solved my problem.


: