map<string,string> error

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 78
Reputation: drjay1627 is an unknown quantity at this point 
Solved Threads: 1
drjay1627 drjay1627 is offline Offline
Junior Poster in Training

map<string,string> error

 
0
  #1
Nov 30th, 2008
I need help with inserting a string for both key and value to a map.
  1.  
  2. while(!myHuffFile.eof()){
  3. string word, code;
  4. int freq;
  5. myHuffFile >> word >> freq >> code;
  6. if(word == ""){
  7. break;
  8. }else{
  9. _fileMap.insert(pair<string,string>(word,code));
  10. _freqMap.insert(pair<string,int>(word,freq));
  11. }
  12. }


error:

error: conversion from `std::_Rb_tree_iterator<std::pair<const std::string, std::string> >' to non-scalar type `std::_Rb_tree_iterator<std::pair<const std::string, int> >' requested

can you please help me with this.

thanks

drjay
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 392
Reputation: StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light 
Solved Threads: 72
StuXYZ StuXYZ is offline Offline
Posting Whiz

Re: map<string,string> error

 
0
  #2
Nov 30th, 2008
As written there is nothing wrong with this (except I think that you would benefit from a typedef. e.g.
  1. typedef std::map<std::string,int> mTYPE;
  2. mTYPE aMap;
  3. //....
  4. aMap.insert(mTYPE::value_type(word,i));

However, I would guess that you have swapped the declarations of fileMap and freqMap.

It that is not the problem, please make a short test program and post that.
Last edited by StuXYZ; Nov 30th, 2008 at 6:15 pm. Reason: error on code tag
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 78
Reputation: drjay1627 is an unknown quantity at this point 
Solved Threads: 1
drjay1627 drjay1627 is offline Offline
Junior Poster in Training

Re: map<string,string> error

 
0
  #3
Nov 30th, 2008
there are two maps.
_fileMap<string,string> and the other is _freqMap<string, int>

_freqMap works fine but _fileMap doesn't. I don't think typedef will work here. I'll try it though.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 78
Reputation: drjay1627 is an unknown quantity at this point 
Solved Threads: 1
drjay1627 drjay1627 is offline Offline
Junior Poster in Training

Re: map<string,string> error

 
0
  #4
Nov 30th, 2008
i figured it out! thanks!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC