Results 1 to 16 of 16

Thread: hash_multimap

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Posts
    91
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    4

    Default Re: hash_multimap

    Wow, you are right. The API of both g++ and vc++ is same; just have to insert the required headers. I have the same program working for both g++ and vc++ 2005 right now.
    Here is the code:

    Qt Code:
    1. //VC++
    2. #include<iostream>
    3. #include<cstdio>
    4. #include<hash_map>
    5. using namespace std;
    6. using namespace stdext;
    7. int main(int argc,char** argv)
    8. {
    9. hash_map<int,int> mapping;
    10. hash_map<int,int>::const_iterator miter;
    11.  
    12. mapping.insert(pair<int,int>(1,100));
    13. mapping.insert(pair<int,int>(2,200));
    14. miter = mapping.find(1);
    15.  
    16. if(miter == mapping.end())
    17. cout << "Not found";
    18. else
    19. cout << miter->first << " = " << miter->second;
    20.  
    21.  
    22. getchar();
    23. return 0;
    24. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //g++
    2. #include<iostream>
    3. #include<cstdio>
    4. #include<ext/hash_map>
    5. using namespace std;
    6. using namespace __gnu_cxx;
    7. int main(int argc,char** argv)
    8. {
    9. hash_map<int,int> mapping;
    10. hash_map<int,int>::const_iterator miter;
    11.  
    12. mapping.insert(pair<int,int>(1,100));
    13. mapping.insert(pair<int,int>(2,200));
    14. miter = mapping.find(1);
    15.  
    16. if(miter == mapping.end())
    17. cout << "Not found";
    18. else
    19. cout << miter->first << " = " << miter->second;
    20.  
    21.  
    22. getchar();
    23. return 0;
    24. }
    To copy to clipboard, switch view to plain text mode 

    However I am running into some problem with hash_map<string,string> for both the compilers. I am sure there is some compare function that needs to be defined for strings or is there something already available ?
    Humans make mistake because there is really NO patch for HUMAN STUPIDITY

  2. #2
    Join Date
    Feb 2006
    Posts
    91
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    4

    Default Re: hash_multimap

    BTW, how can I combine both these files into one so that both the compilers can compile it. Is there some flag that needs to be checked to find out if the compiler is VC++ or g++ ?
    Humans make mistake because there is really NO patch for HUMAN STUPIDITY

  3. #3
    Join Date
    Oct 2006
    Posts
    279
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    6
    Thanked 40 Times in 39 Posts

    Default Re: hash_multimap

    Qt Code:
    1. #ifdef Q_CC_MSVC
    2. #include<hash_map>
    3. using namespace stdext;
    4. #endif
    5.  
    6. #ifdef Q_CC_GNU
    7. #include<ext/hash_map>
    8. using namespace __gnu_cxx;
    9. #endif
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Posts
    91
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    4

    Default Re: hash_multimap

    Quote Originally Posted by spud View Post
    Qt Code:
    1. #ifdef Q_CC_MSVC
    2. #include<hash_map>
    3. using namespace stdext;
    4. #endif
    5.  
    6. #ifdef Q_CC_GNU
    7. #include<ext/hash_map>
    8. using namespace __gnu_cxx;
    9. #endif
    To copy to clipboard, switch view to plain text mode 

    That certainly didn't work. Is that some QT preprocessor that does the same thing? I opened up the glut.h file and saw how they have done it so I got upto here.

    Qt Code:
    1. #include<iostream>
    2. #include<cstdio>
    3.  
    4. #if defined(__MINGW32__)
    5. #include<ext/hash_map>
    6. using namespace __gnu_cxx;
    7. #endif
    8.  
    9. #if defined(_MSC_VER)
    10. #include<hash_map>
    11. using namespace stdext;
    12. #endif
    13.  
    14. #include<iostream>
    15. #include<cstdio>
    16.  
    17. using namespace std;
    18.  
    19. int main(int argc,char** argv)
    20. {
    21. hash_map<int,int> mapping;
    22. hash_map<int,int>::const_iterator miter;
    23.  
    24. mapping.insert(pair<int,int>(1,100));
    25. mapping.insert(pair<int,int>(2,200));
    26. miter = mapping.find(1);
    27.  
    28. if(miter == mapping.end())
    29. cout << "Not found";
    30. else
    31. cout << miter->first << " = " << miter->second;
    32.  
    33.  
    34. getchar();
    35. return 0;
    36. }
    To copy to clipboard, switch view to plain text mode 
    The preprocessors have always confused me a bit. Is there a list of all the preprocessors that can be used (at least the more common ones ). Can anyone point to some good resource about types of general preprocessors or may be list some common ones out here ?
    Humans make mistake because there is really NO patch for HUMAN STUPIDITY

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.