Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 C++ Iterators, using MinGW
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
riveryu




PostPosted: 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...?
Sponsor
Sponsor
Sponsor
sponsor
saltpro15




PostPosted: 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
riveryu




PostPosted: 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.
saltpro15




PostPosted: 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
sharvil




PostPosted: 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 */
}
[Gandalf]




PostPosted: Sun Mar 22, 2009 12:25 am   Post subject: RE:C++ Iterators, using MinGW

MinGW is the Windows port of the GCC compiler. Smile
md




PostPosted: 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).
riveryu




PostPosted: Sun Mar 22, 2009 4:43 pm   Post subject: RE:C++ Iterators, using MinGW

Thanks guys, I solved my problem.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: