User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 455,965 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,684 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1090 | Replies: 2 | Solved
Reply
Join Date: Sep 2006
Location: Michigan State University, United States
Posts: 232
Reputation: FireSBurnsmuP is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
FireSBurnsmuP's Avatar
FireSBurnsmuP FireSBurnsmuP is offline Offline
Posting Whiz in Training

iterator error of unknown meaning - STL map

  #1  
Nov 20th, 2007
Alright, here's the code:
	for ( map<string,int>::iterator word = mostUsed.begin() ;
		word != mostUsed.end() ; word++ )

and the error by g++ - (using make)
	error: conversion from 'std::_Rb_tree_const_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >; int> >' to non-scalar type 'std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >; int> >' requested

Okay... what in the name of the gods? I used this code before in the program and nothing screwed up. here's that for-loop:
for( map<string,int>::iterator x = fauxIn.begin() ; x != fauxIn.end() ; x++ )

I don't see the problem, apparentlymap<string,int>::iterator word = mostUsed.begin() is the problem, but I don't see anything wrong.

Help!
Damn the man! Save the Empire!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2006
Location: india
Posts: 1,084
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Rep Power: 9
Solved Threads: 163
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: iterator error of unknown meaning - STL map

  #2  
Nov 20th, 2007
mostUsed is a const. use a const_iterator. also a prefix increment instead of a postfix (efficiency)
for ( map<string,int>::const_iterator word = mostUsed.begin() ;
		word != mostUsed.end() ; ++word ) { /*...*/
Reply With Quote  
Join Date: Sep 2006
Location: Michigan State University, United States
Posts: 232
Reputation: FireSBurnsmuP is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
FireSBurnsmuP's Avatar
FireSBurnsmuP FireSBurnsmuP is offline Offline
Posting Whiz in Training

Re: iterator error of unknown meaning - STL map

  #3  
Dec 3rd, 2007
Wow, thanks! That allowed me to compile for the first time in a month. ^_^ I wouldn't have thought to make it a const_iterator instead of a regular iterator.

Thanks!
Damn the man! Save the Empire!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 9:05 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC