Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Using STL map<...>

Using STL map<...>

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++question
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rostrox
    wrote on last edited by
    #1

    Hello: I built a map<...> in the way showed below. After running program, I do not know if data was loaded correctly. To verify this, I wanted to use "cout", but I do not know how to reference, for example, to the content of dMonto[3] that is in mpCont. Is there a charitable codeguru soul by there? Thanks in advance!!!! #include #include #include #include using namespace std; const int tam=10; struct stTot { string stLey; double dMonto[tam]; }; stTot myTot; map mpCont; int main() { myTot.stLey = "Text one"; for(int i=0; i::iterator it = mpCont.find("one"); // I want to put the "cout" here return 0; } :-O :-O

    B 1 Reply Last reply
    0
    • R Rostrox

      Hello: I built a map<...> in the way showed below. After running program, I do not know if data was loaded correctly. To verify this, I wanted to use "cout", but I do not know how to reference, for example, to the content of dMonto[3] that is in mpCont. Is there a charitable codeguru soul by there? Thanks in advance!!!! #include #include #include #include using namespace std; const int tam=10; struct stTot { string stLey; double dMonto[tam]; }; stTot myTot; map mpCont; int main() { myTot.stLey = "Text one"; for(int i=0; i::iterator it = mpCont.find("one"); // I want to put the "cout" here return 0; } :-O :-O

      B Offline
      B Offline
      Ben Burnett
      wrote on last edited by
      #2

      The folowing should do the trick; cout << (*yourIterator).second << endl; -Ben On the topic of code with no error handling -- It's not poor coding, it's "optimistic" ;)

      L 1 Reply Last reply
      0
      • B Ben Burnett

        The folowing should do the trick; cout << (*yourIterator).second << endl; -Ben On the topic of code with no error handling -- It's not poor coding, it's "optimistic" ;)

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        So far I've seen two examples using the syntax: (*iter).second to look at the content of a map. Is there something wrong with using the -> operator as in: iter->second Thanx

        M 1 Reply Last reply
        0
        • L Lost User

          So far I've seen two examples using the syntax: (*iter).second to look at the content of a map. Is there something wrong with using the -> operator as in: iter->second Thanx

          M Offline
          M Offline
          markkuk
          wrote on last edited by
          #4

          My STL book ("The C++ Standard Library: A Tutorial and Reference" by Nicolai Josuttis) tells that:

          In some older environments, operator -> might not work yet for iterators

          MSVC's STL implementation seems to be an "older environment", using (*iter).member is always safe.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups