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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. What's wrong with this code?

What's wrong with this code?

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++visual-studiotutorialquestion
4 Posts 3 Posters 2 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.
  • J Offline
    J Offline
    Jonathan Gilligan
    wrote on last edited by
    #1

    Can anyone tell me why this code

    #include <map>
    
    std::map<std::string, int> foo;
    
    int test_stl(std::string key)
    {
        return foo.find(key)->second;
    }
    

    Gives me about a page of STL compilation errors in Visual Studio .NET? Can anyone give me an example of working code that uses a hash_map or a map with an std::string key type? Why couldn't Science, in the long run, serve As well as one's uncleared lunch-table or Mme X en Culottes de Matador?     James Merrill

    D Z 2 Replies Last reply
    0
    • J Jonathan Gilligan

      Can anyone tell me why this code

      #include <map>
      
      std::map<std::string, int> foo;
      
      int test_stl(std::string key)
      {
          return foo.find(key)->second;
      }
      

      Gives me about a page of STL compilation errors in Visual Studio .NET? Can anyone give me an example of working code that uses a hash_map or a map with an std::string key type? Why couldn't Science, in the long run, serve As well as one's uncleared lunch-table or Mme X en Culottes de Matador?     James Merrill

      D Offline
      D Offline
      Dave Bryant
      wrote on last edited by
      #2

      If you actually include the compile errors (or at least the first few), then it will make it a lot easier to determine what the problem is. Dave http://www.cloudsofheaven.org

      1 Reply Last reply
      0
      • J Jonathan Gilligan

        Can anyone tell me why this code

        #include <map>
        
        std::map<std::string, int> foo;
        
        int test_stl(std::string key)
        {
            return foo.find(key)->second;
        }
        

        Gives me about a page of STL compilation errors in Visual Studio .NET? Can anyone give me an example of working code that uses a hash_map or a map with an std::string key type? Why couldn't Science, in the long run, serve As well as one's uncleared lunch-table or Mme X en Culottes de Matador?     James Merrill

        Z Offline
        Z Offline
        ZoogieZork
        wrote on last edited by
        #3

        Looks like you just need to #include <string>:

        #include <map>
        #include <string>
        std::map<std::string, int> foo;
        int test_stl(std::string key){
        return foo.find(key)->second;
        }

        - Mike

        J 1 Reply Last reply
        0
        • Z ZoogieZork

          Looks like you just need to #include <string>:

          #include <map>
          #include <string>
          std::map<std::string, int> foo;
          int test_stl(std::string key){
          return foo.find(key)->second;
          }

          - Mike

          J Offline
          J Offline
          Jonathan Gilligan
          wrote on last edited by
          #4

          Duh! Thanks for setting me straight.

          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