DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   map<string,string> error (http://www.daniweb.com/forums/thread160137.html)

drjay1627 Nov 30th, 2008 5:58 pm
map<string,string> error
 
I need help with inserting a string for both key and value to a map.

while(!myHuffFile.eof()){
                string word, code;
                int freq;
                myHuffFile >> word >> freq >> code;
                if(word == ""){
                        break;
                }else{
                        _fileMap.insert(pair<string,string>(word,code));
                        _freqMap.insert(pair<string,int>(word,freq));
                }
        }


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

StuXYZ Nov 30th, 2008 6:14 pm
Re: map<string,string> error
 
As written there is nothing wrong with this (except I think that you would benefit from a typedef. e.g.
typedef std::map<std::string,int> mTYPE;
mTYPE aMap;
//....
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.

drjay1627 Nov 30th, 2008 6:29 pm
Re: map<string,string> error
 
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.

drjay1627 Nov 30th, 2008 8:57 pm
Re: map<string,string> error
 
i figured it out! thanks!


All times are GMT -4. The time now is 3:05 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC