std::maps

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

    #1

    std::maps

    Can I have maps with following properties?
    Key= A character strings...
    Value=A structure... Members of structure will be two character
    strings....

    If yes how to do that?Can anyone tell me the detail syntax of that...

    How to compare a character string with one of the value in that
    structure?????? ??

  • red floyd

    #2
    Re: std::maps

    Anamika wrote:
    Can I have maps with following properties?
    Key= A character strings...
    Value=A structure... Members of structure will be two character
    strings....
    >
    If yes how to do that?Can anyone tell me the detail syntax of that...
    >
    How to compare a character string with one of the value in that
    structure?????? ??
    >
    Yes you can, but better is having the key be a std::string.

    i.e.:

    std::map<std::s tring, my_structmy_map ;

    Comment

    • Mike Wahler

      #3
      Re: std::maps


      "Anamika" <shraddhajoshi8 4@gmail.comwrot e in message
      news:1161921248 .048554.133690@ k70g2000cwa.goo glegroups.com.. .

      Question 1:
      Can I have maps with following properties?
      Key= A character strings...
      Value=A structure... Members of structure will be two character
      strings....
      >
      If yes how to do that?Can anyone tell me the detail syntax of that...
      >
      Question 2:
      How to compare a character string with one of the value in that
      structure?????? ??
      Since you don't give much context, the following code is
      a literal answer to your questions. Given more information
      about the purpose of your program, I suspect there may be
      a more appropriate solution(s).

      #include <iostream>
      #include <map>
      #include <string>

      /* Question 1 answer: */

      struct S /* a structure for storing two strings */
      {
      std::string one;
      std::string two;
      };

      int main()
      {
      std::map<std::s tring, Sm; /* the map */


      /* Question 2 answer: */

      S s = {"hello", "world"}; /* a populated structure */
      std::string comp = "world"; /* a string to compare with */

      /* compare 'comp' with one of the struct's strings */
      if(comp == s.two)
      std::cout << "match\n";
      else
      std::cout << "no match\n";

      return 0;
      }

      Recommended reading:



      -Mike


      Comment

      • Anamika

        #4
        Re: std::maps

        Thanks for the help mike...but I am still suffering from problem...I
        tried your solution,but it is not working...There are some errors
        regarding maps...
        Will that work in visual studio?
        please help me out...

        thanks...

        Mike Wahler wrote:
        "Anamika" <shraddhajoshi8 4@gmail.comwrot e in message
        news:1161921248 .048554.133690@ k70g2000cwa.goo glegroups.com.. .
        >
        Question 1:
        >
        Can I have maps with following properties?
        Key= A character strings...
        Value=A structure... Members of structure will be two character
        strings....

        If yes how to do that?Can anyone tell me the detail syntax of that...
        >
        Question 2:
        >
        How to compare a character string with one of the value in that
        structure?????? ??
        >
        Since you don't give much context, the following code is
        a literal answer to your questions. Given more information
        about the purpose of your program, I suspect there may be
        a more appropriate solution(s).
        >
        #include <iostream>
        #include <map>
        #include <string>
        >
        /* Question 1 answer: */
        >
        struct S /* a structure for storing two strings */
        {
        std::string one;
        std::string two;
        };
        >
        int main()
        {
        std::map<std::s tring, Sm; /* the map */
        >
        >
        /* Question 2 answer: */
        >
        S s = {"hello", "world"}; /* a populated structure */
        std::string comp = "world"; /* a string to compare with */
        >
        /* compare 'comp' with one of the struct's strings */
        if(comp == s.two)
        std::cout << "match\n";
        else
        std::cout << "no match\n";
        >
        return 0;
        }
        >
        Recommended reading:
        >

        >
        -Mike

        Comment

        • Mike Wahler

          #5
          Re: std::maps


          "Anamika" <shraddhajoshi8 4@gmail.comwrot e in message
          news:1162011912 .148624.72480@m 7g2000cwm.googl egroups.com...
          Thanks for the help mike...but I am still suffering from problem...I
          tried your solution,but it is not working...There are some errors
          regarding maps...
          Will that work in visual studio?
          please help me out...
          Please don't top post.

          What I wrote was not intended to be a 'solution' to
          anything, only to illustrate how to do the specific
          things you asked about.

          When you say 'not working', do you mean it failed to compile?
          If so, post the exact code you tried, with the exact error messages
          you got.

          Did it compile but behave in a way other than what you expected?
          If so, state what you expected, and what actually happened.

          -Mike




          Comment

          • Anamika

            #6
            Re: std::maps

            This is the code what I tried...


            #include <iostream>
            #include <map>
            #include <string>


            /* Question 1 answer: */


            typedef struct S1 /* a structure for storing two strings */
            {
            std::string one;
            std::string two;



            }S;


            int main()
            {
            std::map<std::s tring, Sm; /* the map */

            /* Question 2 answer: */

            S s ; /* a populated structure */
            s.one="hello";
            s.two="world";
            std::string comp = "world"; /* a string to compare with */


            /* compare 'comp' with one of the struct's strings */
            if(comp == s.two)
            std::cout << "match\n";
            else
            std::cout << "no match\n";


            return 0;



            }


            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            Actually there is not much difference,but I just change the way of
            initialising the structre...
            The previous one was giving me error...
            This one is not giving me any error,but giving me 77 warnings...
            What wrong with it?Can you compile this and give me the answer?


            The actual thing what I want is....

            I want to maintain the list of users,there passwords & and a character
            string which is specific to the user...
            Even I want to access these strings,wheneve r I want...
            either to use or to comare...
            These are my requirement..My project is incomplete just because of
            that.....
            Mike Wahler wrote:
            "Anamika" <shraddhajoshi8 4@gmail.comwrot e in message
            news:1162011912 .148624.72480@m 7g2000cwm.googl egroups.com...
            Thanks for the help mike...but I am still suffering from problem...I
            tried your solution,but it is not working...There are some errors
            regarding maps...
            Will that work in visual studio?
            please help me out...
            >
            Please don't top post.
            >
            What I wrote was not intended to be a 'solution' to
            anything, only to illustrate how to do the specific
            things you asked about.
            >
            When you say 'not working', do you mean it failed to compile?
            If so, post the exact code you tried, with the exact error messages
            you got.
            >
            Did it compile but behave in a way other than what you expected?
            If so, state what you expected, and what actually happened.
            >
            -Mike

            Comment

            • Mike Wahler

              #7
              Re: std::maps


              "Anamika" <shraddhajoshi8 4@gmail.comwrot e in message
              news:1162108208 .911911.169140@ h48g2000cwc.goo glegroups.com.. .
              This is the code what I tried...
              >
              >
              #include <iostream>
              #include <map>
              #include <string>
              >
              >
              /* Question 1 answer: */
              >
              >
              typedef struct S1 /* a structure for storing two strings */
              {
              std::string one;
              std::string two;
              >
              >
              >
              }S;
              >
              >
              int main()
              {
              std::map<std::s tring, Sm; /* the map */
              >
              /* Question 2 answer: */
              >
              S s ; /* a populated structure */
              s.one="hello";
              s.two="world";
              std::string comp = "world"; /* a string to compare with */
              >
              >
              /* compare 'comp' with one of the struct's strings */
              if(comp == s.two)
              std::cout << "match\n";
              else
              std::cout << "no match\n";
              >
              >
              return 0;
              >
              >
              >
              }
              >
              >
              /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
              Actually there is not much difference,but I just change the way of
              initialising the structre...
              The previous one was giving me error...
              This one is not giving me any error,but giving me 77 warnings...
              What are the warnings?

              What wrong with it?Can you compile this and give me the answer?
              It (the original code I posted) compiled for me with
              no warnings or errors.

              -Mike


              Comment

              • Anamika

                #8
                Re: std::maps

                c:\program files\microsoft visual studio\vc98\inc lude\xtree(120) :
                warning C4786:
                'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                >,std::pair<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar const ,
                S>,std::map<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _string<char,st d::char_traits< char>,std
                ::allocator<cha r >,std::allocato r<S' : identifier was truncated
                to '255' characters in the debug information
                c:\program files\microsoft visual studio\vc98\inc lude\map(46) :
                see reference to class template instantiation
                'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                >,std::pair<std ::basic_string< char,std::char_ traits<
                char>,std::allo cator<char const
                ,S>,std::map<st d::basic_string <char,std::char _traits<char>,s td::allocator<c har>
                >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _st
                ring<char,std:: char_traits<cha r>,std::allocat or<char
                >,std::allocato r<S' being compiled
                c:\text1.cpp(21 ) : see reference to class template
                instantiation
                'std::map<std:: basic_string<ch ar,std::char_tr aits<char>,std: :allocator<char >
                >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r
                <S' being compiled
                c:\program files\microsoft visual studio\vc98\inc lude\xtree(120) :
                warning C4786:
                'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                >,std::pair<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar const ,
                S>,std::map<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _string<char,st d::char_traits< char>,std
                ::allocator<cha r >,std::allocato r<S::const_iter ator' : identifier
                was truncated to '255' characters in the debug information
                c:\program files\microsoft visual studio\vc98\inc lude\map(46) :
                see reference to class template instantiation
                'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                >,std::pair<std ::basic_string< char,std::char_ traits<
                char>,std::allo cator<char const
                ,S>,std::map<st d::basic_string <char,std::char _traits<char>,s td::allocator<c har>
                >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _st
                ring<char,std:: char_traits<cha r>,std::allocat or<char
                >,std::allocato r<S' being compiled
                c:\text1.cpp(21 ) : see reference to class template
                instantiation
                'std::map<std:: basic_string<ch ar,std::char_tr aits<char>,std: :allocator<char >
                >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r
                <S' being compiled
                c:\program files\microsoft visual studio\vc98\inc lude\xtree(120) :
                warning C4786:
                'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                >,std::pair<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar const ,
                S>,std::map<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _string<char,st d::char_traits< char>,std
                ::allocator<cha r >,std::allocato r<S::iterator' : identifier was
                truncated to '255' characters in the debug information
                c:\program files\microsoft visual studio\vc98\inc lude\map(46) :
                see reference to class template instantiation
                'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                >,std::pair<std ::basic_string< char,std::char_ traits<
                char>,std::allo cator<char const
                ,S>,std::map<st d::basic_string <char,std::char _traits<char>,s td::allocator<c har>
                >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _st
                ring<char,std:: char_traits<cha r>,std::allocat or<char
                >,std::allocato r<S' being compiled
                c:\text1.cpp(21 ) : see reference to class template
                instantiation
                'std::map<std:: basic_string<ch ar,std::char_tr aits<char>,std: :allocator<char >
                >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r
                <S' being compiled
                c:\program files\microsoft visual studio\vc98\inc lude\xtree(120) :
                warning C4786:
                'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                >,std::pair<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar const ,
                S>,std::map<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _string<char,st d::char_traits< char>,std
                ::allocator<cha r >,std::allocato r<S::_Node' : identifier was
                truncated to '255' characters in the debug information
                c:\program files\microsoft visual studio\vc98\inc lude\map(46) :
                see reference to class template instantiation
                'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                >,std::pair<std ::basic_string< char,std::char_ traits<
                char>,std::allo cator<char const
                ,S>,std::map<st d::basic_string <char,std::char _traits<char>,s td::allocator<c har>
                >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _st
                ring<char,std:: char_traits<cha r>,std::allocat or<char
                >,std::allocato r<S' being compiled
                c:\text1.cpp(21 ) : see reference to class template
                instantiation
                'std::map<std:: basic_string<ch ar,std::char_tr aits<char>,std: :allocator<char >
                >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r
                <S' being compiled
                c:\program files\microsoft visual studio\vc98\inc lude\xtree(120) :
                warning C4786:
                'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                >,std::pair<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar const ,
                S>,std::map<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _string<char,st d::char_traits< char>,std
                ::allocator<cha r >,std::allocato r<S::const_iter ator' : identifier
                was truncated to '255' characters in the debug information
                c:\program files\microsoft visual studio\vc98\inc lude\map(46) :
                see reference to class template instantiation
                'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                >,std::pair<std ::basic_string< char,std::char_ traits<
                char>,std::allo cator<char const
                ,S>,std::map<st d::basic_string <char,std::char _traits<char>,s td::allocator<c har>
                >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _st
                ring<char,std:: char_traits<cha r>,std::allocat or<char
                >,std::allocato r<S' being compiled
                c:\text1.cpp(21 ) : see reference to class template
                instantiation
                'std::map<std:: basic_string<ch ar,std::char_tr aits<char>,std: :allocator<char >
                >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r
                <S' being compiled
                c:\text1.cpp(26 ) : error C2552: 's' : non-aggregates cannot be
                initialized with initializer list
                Error executing cl.exe.
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                This error and warnings I get, when I compiled that code...
                And if I do the changes to avoid that error,I get 77 warnings.The same
                code I posted you....

                Mike Wahler wrote:
                "Anamika" <shraddhajoshi8 4@gmail.comwrot e in message
                news:1162108208 .911911.169140@ h48g2000cwc.goo glegroups.com.. .
                This is the code what I tried...


                #include <iostream>
                #include <map>
                #include <string>


                /* Question 1 answer: */


                typedef struct S1 /* a structure for storing two strings */
                {
                std::string one;
                std::string two;



                }S;


                int main()
                {
                std::map<std::s tring, Sm; /* the map */

                /* Question 2 answer: */

                S s ; /* a populated structure */
                s.one="hello";
                s.two="world";
                std::string comp = "world"; /* a string to compare with */


                /* compare 'comp' with one of the struct's strings */
                if(comp == s.two)
                std::cout << "match\n";
                else
                std::cout << "no match\n";


                return 0;



                }


                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                Actually there is not much difference,but I just change the way of
                initialising the structre...
                The previous one was giving me error...
                This one is not giving me any error,but giving me 77 warnings...
                >
                What are the warnings?
                >
                >
                What wrong with it?Can you compile this and give me the answer?
                >
                It (the original code I posted) compiled for me with
                no warnings or errors.
                >
                -Mike

                Comment

                • Anamika

                  #9
                  Re: std::maps

                  c:\program files\microsoft visual studio\vc98\inc lude\xtree(120) :
                  warning C4786:
                  'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                  >,std::pair<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar const ,
                  S>,std::map<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                  >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _string<char,st d::char_traits< char>,std
                  ::allocator<cha r >,std::allocato r<S' : identifier was truncated
                  to '255' characters in the debug information
                  c:\program files\microsoft visual studio\vc98\inc lude\map(46) :
                  see reference to class template instantiation
                  'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                  >,std::pair<std ::basic_string< char,std::char_ traits<
                  char>,std::allo cator<char const
                  ,S>,std::map<st d::basic_string <char,std::char _traits<char>,s td::allocator<c har>
                  >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _st
                  ring<char,std:: char_traits<cha r>,std::allocat or<char
                  >,std::allocato r<S' being compiled
                  c:\text1.cpp(21 ) : see reference to class template
                  instantiation
                  'std::map<std:: basic_string<ch ar,std::char_tr aits<char>,std: :allocator<char >
                  >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r
                  <S' being compiled
                  c:\program files\microsoft visual studio\vc98\inc lude\xtree(120) :
                  warning C4786:
                  'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                  >,std::pair<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar const ,
                  S>,std::map<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                  >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _string<char,st d::char_traits< char>,std
                  ::allocator<cha r >,std::allocato r<S::const_iter ator' : identifier
                  was truncated to '255' characters in the debug information
                  c:\program files\microsoft visual studio\vc98\inc lude\map(46) :
                  see reference to class template instantiation
                  'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                  >,std::pair<std ::basic_string< char,std::char_ traits<
                  char>,std::allo cator<char const
                  ,S>,std::map<st d::basic_string <char,std::char _traits<char>,s td::allocator<c har>
                  >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _st
                  ring<char,std:: char_traits<cha r>,std::allocat or<char
                  >,std::allocato r<S' being compiled
                  c:\text1.cpp(21 ) : see reference to class template
                  instantiation
                  'std::map<std:: basic_string<ch ar,std::char_tr aits<char>,std: :allocator<char >
                  >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r
                  <S' being compiled
                  c:\program files\microsoft visual studio\vc98\inc lude\xtree(120) :
                  warning C4786:
                  'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                  >,std::pair<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar const ,
                  S>,std::map<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                  >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _string<char,st d::char_traits< char>,std
                  ::allocator<cha r >,std::allocato r<S::iterator' : identifier was
                  truncated to '255' characters in the debug information
                  c:\program files\microsoft visual studio\vc98\inc lude\map(46) :
                  see reference to class template instantiation
                  'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                  >,std::pair<std ::basic_string< char,std::char_ traits<
                  char>,std::allo cator<char const
                  ,S>,std::map<st d::basic_string <char,std::char _traits<char>,s td::allocator<c har>
                  >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _st
                  ring<char,std:: char_traits<cha r>,std::allocat or<char
                  >,std::allocato r<S' being compiled
                  c:\text1.cpp(21 ) : see reference to class template
                  instantiation
                  'std::map<std:: basic_string<ch ar,std::char_tr aits<char>,std: :allocator<char >
                  >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r
                  <S' being compiled
                  c:\program files\microsoft visual studio\vc98\inc lude\xtree(120) :
                  warning C4786:
                  'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                  >,std::pair<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar const ,
                  S>,std::map<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                  >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _string<char,st d::char_traits< char>,std
                  ::allocator<cha r >,std::allocato r<S::_Node' : identifier was
                  truncated to '255' characters in the debug information
                  c:\program files\microsoft visual studio\vc98\inc lude\map(46) :
                  see reference to class template instantiation
                  'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                  >,std::pair<std ::basic_string< char,std::char_ traits<
                  char>,std::allo cator<char const
                  ,S>,std::map<st d::basic_string <char,std::char _traits<char>,s td::allocator<c har>
                  >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _st
                  ring<char,std:: char_traits<cha r>,std::allocat or<char
                  >,std::allocato r<S' being compiled
                  c:\text1.cpp(21 ) : see reference to class template
                  instantiation
                  'std::map<std:: basic_string<ch ar,std::char_tr aits<char>,std: :allocator<char >
                  >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r
                  <S' being compiled
                  c:\program files\microsoft visual studio\vc98\inc lude\xtree(120) :
                  warning C4786:
                  'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                  >,std::pair<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar const ,
                  S>,std::map<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                  >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _string<char,st d::char_traits< char>,std
                  ::allocator<cha r >,std::allocato r<S::const_iter ator' : identifier
                  was truncated to '255' characters in the debug information
                  c:\program files\microsoft visual studio\vc98\inc lude\map(46) :
                  see reference to class template instantiation
                  'std::_Tree<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar>
                  >,std::pair<std ::basic_string< char,std::char_ traits<
                  char>,std::allo cator<char const
                  ,S>,std::map<st d::basic_string <char,std::char _traits<char>,s td::allocator<c har>
                  >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r<S::_Kfn,std:: less<std::basic _st
                  ring<char,std:: char_traits<cha r>,std::allocat or<char
                  >,std::allocato r<S' being compiled
                  c:\text1.cpp(21 ) : see reference to class template
                  instantiation
                  'std::map<std:: basic_string<ch ar,std::char_tr aits<char>,std: :allocator<char >
                  >,S,std::less<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char >,std::allocato r
                  <S' being compiled
                  c:\text1.cpp(26 ) : error C2552: 's' : non-aggregates cannot be
                  initialized with initializer list
                  Error executing cl.exe.
                  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                  This error and warnings I get, when I compiled that code...
                  And if I do the changes to avoid that error,I get 77 warnings.The same
                  code I posted you....

                  Mike Wahler wrote:
                  "Anamika" <shraddhajoshi8 4@gmail.comwrot e in message
                  news:1162108208 .911911.169140@ h48g2000cwc.goo glegroups.com.. .
                  This is the code what I tried...


                  #include <iostream>
                  #include <map>
                  #include <string>


                  /* Question 1 answer: */


                  typedef struct S1 /* a structure for storing two strings */
                  {
                  std::string one;
                  std::string two;



                  }S;


                  int main()
                  {
                  std::map<std::s tring, Sm; /* the map */

                  /* Question 2 answer: */

                  S s ; /* a populated structure */
                  s.one="hello";
                  s.two="world";
                  std::string comp = "world"; /* a string to compare with */


                  /* compare 'comp' with one of the struct's strings */
                  if(comp == s.two)
                  std::cout << "match\n";
                  else
                  std::cout << "no match\n";


                  return 0;



                  }


                  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                  Actually there is not much difference,but I just change the way of
                  initialising the structre...
                  The previous one was giving me error...
                  This one is not giving me any error,but giving me 77 warnings...
                  >
                  What are the warnings?
                  >
                  >
                  What wrong with it?Can you compile this and give me the answer?
                  >
                  It (the original code I posted) compiled for me with
                  no warnings or errors.
                  >
                  -Mike

                  Comment

                  Working...