Map iterator to string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Micheal Smith

    Map iterator to string

    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.

  • Victor Bazarov

    #2
    Re: Map iterator to string

    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

    Comment

    • Micheal Smith

      #3
      Re: Map iterator to string

      On 2008-10-20 13:43:58 -0500, Victor Bazarov <v.Abazarov@com Acast.netsaid:
      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.

      Comment

      • Ian Collins

        #4
        Re: Map iterator to string

        Micheal Smith wrote:
        On 2008-10-20 13:43:58 -0500, Victor Bazarov <v.Abazarov@com Acast.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

        Comment

        • Juha Nieminen

          #5
          Re: Map iterator to string

          Micheal Smith wrote:
          On 2008-10-20 13:43:58 -0500, Victor Bazarov <v.Abazarov@com Acast.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<someth ing, 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
          "yourIterat or->second", which is probably the answer you are looking for).

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

          Comment

          • Gernot Frisch

            #6
            Re: Map iterator to string

            Seemingly what you have is a std::map<someth ing, 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
            "yourIterat or->second", which is probably the answer you are looking for).
            or:
            my_iterator->first

            for std::map<std::s tring, anything>;

            Comment

            Working...