[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Map iterator to string

Micheal Smith

10/20/2008 6:42:00 PM

I'm looking for a good method to convert a map::iterator to a
std::string. I've tried googling for a while, but haven't come up with
much. Perhaps I'm kludging things here. Either way any advice would
be greatly appreciated.

5 Answers

Victor Bazarov

10/20/2008 6:44:00 PM

0

Micheal Smith wrote:
> I'm looking for a good method to convert a map::iterator to a
> std::string. I've tried googling for a while, but haven't come up with
> much. Perhaps I'm kludging things here. Either way any advice would be
> greatly appreciated.
>

What are you hoping to get from the conversion?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

Micheal Smith

10/20/2008 6:55:00 PM

0

On 2008-10-20 13:43:58 -0500, Victor Bazarov <v.Abazarov@comAcast.net> said:

> Micheal Smith wrote:
>> I'm looking for a good method to convert a map::iterator to a
>> std::string. I've tried googling for a while, but haven't come up with
>> much. Perhaps I'm kludging things here. Either way any advice would
>> be greatly appreciated.
>>
>
> What are you hoping to get from the conversion?
>
> V

I have a member function that searches a map for a key. The value tied
to the given key should be a std::string. It just seemed like a better
idea to return the original std::string, than simply an iterator.

Ian Collins

10/20/2008 6:57:00 PM

0

Micheal Smith wrote:
> On 2008-10-20 13:43:58 -0500, Victor Bazarov <v.Abazarov@comAcast.net>
> said:
>
>> Micheal Smith wrote:
>>> I'm looking for a good method to convert a map::iterator to a
>>> std::string. I've tried googling for a while, but haven't come up
>>> with much. Perhaps I'm kludging things here. Either way any advice
>>> would be greatly appreciated.
>>>
>>
>> What are you hoping to get from the conversion?
>>
>> V
>
> I have a member function that searches a map for a key. The value tied
> to the given key should be a std::string. It just seemed like a better
> idea to return the original std::string, than simply an iterator.
>
What's wrong with using iterator->second?

--
Ian Collins

Juha Nieminen

10/20/2008 7:43:00 PM

0

Micheal Smith wrote:
> On 2008-10-20 13:43:58 -0500, Victor Bazarov <v.Abazarov@comAcast.net>
> said:
>
>> Micheal Smith wrote:
>>> I'm looking for a good method to convert a map::iterator to a
>>> std::string. I've tried googling for a while, but haven't come up
>>> with much. Perhaps I'm kludging things here. Either way any advice
>>> would be greatly appreciated.
>>>
>>
>> What are you hoping to get from the conversion?
>>
>> V
>
> I have a member function that searches a map for a key. The value tied
> to the given key should be a std::string. It just seemed like a better
> idea to return the original std::string, than simply an iterator.

Your original post is very poorly written. You are asking in your
original post how to *convert* a map::iterator (what kind of map?) into
a std::string. What does that even mean? Are you trying to generate a
string from the value of the iterator? Are you trying to cast the
iterator into a string? What?

Seemingly what you have is a std::map<something, std::string>, and you
have an iterator pointing to an element of this map, and you want to
dereference the string at that position in the map (which happens with
"yourIterator->second", which is probably the answer you are looking for).

You should be much more specific when you ask such questions.

jt

10/22/2008 2:00:00 PM

0


> Seemingly what you have is a std::map<something, std::string>, and you
> have an iterator pointing to an element of this map, and you want to
> dereference the string at that position in the map (which happens with
> "yourIterator->second", which is probably the answer you are looking for).

or:
my_iterator->first

for std::map<std::string, anything>;