C++ Iterators, using MinGW
Author |
Message |
riveryu
![](http://compsci.ca/v3/uploads/user_avatars/196991102647ae2debe0bf0.jpg)
|
Posted: 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...? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
saltpro15
![](http://compsci.ca/v3/uploads/user_avatars/9776171634ced6278d14c2.png)
|
Posted: Sat Mar 21, 2009 7:18 pm Post subject: RE:C++ Iterators, using MinGW |
|
|
which compiler are you using?
and c++ syntax tag is ![Wink Wink](http://compsci.ca/v3/images/smiles/icon_wink.gif) |
|
|
|
|
![](images/spacer.gif) |
riveryu
![](http://compsci.ca/v3/uploads/user_avatars/196991102647ae2debe0bf0.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
saltpro15
![](http://compsci.ca/v3/uploads/user_avatars/9776171634ced6278d14c2.png)
|
Posted: Sat Mar 21, 2009 7:34 pm Post subject: RE:C++ Iterators, using MinGW |
|
|
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 |
|
|
|
|
![](images/spacer.gif) |
sharvil
|
Posted: 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 */
}
|
|
|
|
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: Sun Mar 22, 2009 12:25 am Post subject: RE:C++ Iterators, using MinGW |
|
|
MinGW is the Windows port of the GCC compiler. ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
md
![](http://compsci.ca/v3/uploads/user_avatars/1849317514ed6c4399768d.png)
|
Posted: 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). |
|
|
|
|
![](images/spacer.gif) |
riveryu
![](http://compsci.ca/v3/uploads/user_avatars/196991102647ae2debe0bf0.jpg)
|
Posted: Sun Mar 22, 2009 4:43 pm Post subject: RE:C++ Iterators, using MinGW |
|
|
Thanks guys, I solved my problem. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|