std::maps

Discussion in 'C++' started by Anamika, Oct 27, 2006.

  1. Anamika

    Anamika Guest

    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????????
    Anamika, Oct 27, 2006
    #1
    1. Advertising

  2. Anamika

    red floyd Guest

    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::string, my_struct> my_map;
    red floyd, Oct 27, 2006
    #2
    1. Advertising

  3. Anamika

    Mike Wahler Guest

    "Anamika" <> wrote in message
    news:...

    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::string, S> m; /* 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:

    www.josuttis.com/libbook

    -Mike
    Mike Wahler, Oct 27, 2006
    #3
  4. Anamika

    Anamika Guest

    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" <> wrote in message
    > news:...
    >
    > 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::string, S> m; /* 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:
    >
    > www.josuttis.com/libbook
    >
    > -Mike
    Anamika, Oct 28, 2006
    #4
  5. Anamika

    Mike Wahler Guest

    "Anamika" <> wrote in message
    news:...
    > 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
    Mike Wahler, Oct 28, 2006
    #5
  6. Anamika

    Anamika Guest

    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::string, S> m; /* 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,whenever I want...
    either to use or to comare...
    These are my requirement..My project is incomplete just because of
    that.....
    Mike Wahler wrote:
    > "Anamika" <> wrote in message
    > news:...
    > > 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
    Anamika, Oct 29, 2006
    #6
  7. Anamika

    Mike Wahler Guest

    "Anamika" <> wrote in message
    news:...
    > 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::string, S> m; /* 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
    Mike Wahler, Oct 29, 2006
    #7
  8. Anamika

    Anamika Guest

    c:\program files\microsoft visual studio\vc98\include\xtree(120) :
    warning C4786:
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,

    S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_string<char,std::char_traits<char>,std

    ::allocator<char> > >,std::allocator<S> >' : identifier was truncated
    to '255' characters in the debug information
    c:\program files\microsoft visual studio\vc98\include\map(46) :
    see reference to class template instantiation
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<

    char>,std::allocator<char> > const
    ,S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_st

    ring<char,std::char_traits<char>,std::allocator<char> >
    >,std::allocator<S> >' being compiled

    c:\text1.cpp(21) : see reference to class template
    instantiation
    'std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator

    <S> >' being compiled
    c:\program files\microsoft visual studio\vc98\include\xtree(120) :
    warning C4786:
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,

    S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_string<char,std::char_traits<char>,std

    ::allocator<char> > >,std::allocator<S> >::const_iterator' : identifier
    was truncated to '255' characters in the debug information
    c:\program files\microsoft visual studio\vc98\include\map(46) :
    see reference to class template instantiation
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<

    char>,std::allocator<char> > const
    ,S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_st

    ring<char,std::char_traits<char>,std::allocator<char> >
    >,std::allocator<S> >' being compiled

    c:\text1.cpp(21) : see reference to class template
    instantiation
    'std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator

    <S> >' being compiled
    c:\program files\microsoft visual studio\vc98\include\xtree(120) :
    warning C4786:
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,

    S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_string<char,std::char_traits<char>,std

    ::allocator<char> > >,std::allocator<S> >::iterator' : identifier was
    truncated to '255' characters in the debug information
    c:\program files\microsoft visual studio\vc98\include\map(46) :
    see reference to class template instantiation
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<

    char>,std::allocator<char> > const
    ,S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_st

    ring<char,std::char_traits<char>,std::allocator<char> >
    >,std::allocator<S> >' being compiled

    c:\text1.cpp(21) : see reference to class template
    instantiation
    'std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator

    <S> >' being compiled
    c:\program files\microsoft visual studio\vc98\include\xtree(120) :
    warning C4786:
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,

    S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_string<char,std::char_traits<char>,std

    ::allocator<char> > >,std::allocator<S> >::_Node' : identifier was
    truncated to '255' characters in the debug information
    c:\program files\microsoft visual studio\vc98\include\map(46) :
    see reference to class template instantiation
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<

    char>,std::allocator<char> > const
    ,S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_st

    ring<char,std::char_traits<char>,std::allocator<char> >
    >,std::allocator<S> >' being compiled

    c:\text1.cpp(21) : see reference to class template
    instantiation
    'std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator

    <S> >' being compiled
    c:\program files\microsoft visual studio\vc98\include\xtree(120) :
    warning C4786:
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,

    S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_string<char,std::char_traits<char>,std

    ::allocator<char> > >,std::allocator<S> >::const_iterator' : identifier
    was truncated to '255' characters in the debug information
    c:\program files\microsoft visual studio\vc98\include\map(46) :
    see reference to class template instantiation
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<

    char>,std::allocator<char> > const
    ,S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_st

    ring<char,std::char_traits<char>,std::allocator<char> >
    >,std::allocator<S> >' being compiled

    c:\text1.cpp(21) : see reference to class template
    instantiation
    'std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator

    <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" <> wrote in message
    > news:...
    > > 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::string, S> m; /* 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
    Anamika, Oct 30, 2006
    #8
  9. Anamika

    Anamika Guest

    c:\program files\microsoft visual studio\vc98\include\xtree(120) :
    warning C4786:
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,

    S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_string<char,std::char_traits<char>,std

    ::allocator<char> > >,std::allocator<S> >' : identifier was truncated
    to '255' characters in the debug information
    c:\program files\microsoft visual studio\vc98\include\map(46) :
    see reference to class template instantiation
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<

    char>,std::allocator<char> > const
    ,S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_st

    ring<char,std::char_traits<char>,std::allocator<char> >
    >,std::allocator<S> >' being compiled

    c:\text1.cpp(21) : see reference to class template
    instantiation
    'std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator

    <S> >' being compiled
    c:\program files\microsoft visual studio\vc98\include\xtree(120) :
    warning C4786:
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,

    S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_string<char,std::char_traits<char>,std

    ::allocator<char> > >,std::allocator<S> >::const_iterator' : identifier
    was truncated to '255' characters in the debug information
    c:\program files\microsoft visual studio\vc98\include\map(46) :
    see reference to class template instantiation
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<

    char>,std::allocator<char> > const
    ,S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_st

    ring<char,std::char_traits<char>,std::allocator<char> >
    >,std::allocator<S> >' being compiled

    c:\text1.cpp(21) : see reference to class template
    instantiation
    'std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator

    <S> >' being compiled
    c:\program files\microsoft visual studio\vc98\include\xtree(120) :
    warning C4786:
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,

    S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_string<char,std::char_traits<char>,std

    ::allocator<char> > >,std::allocator<S> >::iterator' : identifier was
    truncated to '255' characters in the debug information
    c:\program files\microsoft visual studio\vc98\include\map(46) :
    see reference to class template instantiation
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<

    char>,std::allocator<char> > const
    ,S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_st

    ring<char,std::char_traits<char>,std::allocator<char> >
    >,std::allocator<S> >' being compiled

    c:\text1.cpp(21) : see reference to class template
    instantiation
    'std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator

    <S> >' being compiled
    c:\program files\microsoft visual studio\vc98\include\xtree(120) :
    warning C4786:
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,

    S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_string<char,std::char_traits<char>,std

    ::allocator<char> > >,std::allocator<S> >::_Node' : identifier was
    truncated to '255' characters in the debug information
    c:\program files\microsoft visual studio\vc98\include\map(46) :
    see reference to class template instantiation
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<

    char>,std::allocator<char> > const
    ,S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_st

    ring<char,std::char_traits<char>,std::allocator<char> >
    >,std::allocator<S> >' being compiled

    c:\text1.cpp(21) : see reference to class template
    instantiation
    'std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator

    <S> >' being compiled
    c:\program files\microsoft visual studio\vc98\include\xtree(120) :
    warning C4786:
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,

    S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_string<char,std::char_traits<char>,std

    ::allocator<char> > >,std::allocator<S> >::const_iterator' : identifier
    was truncated to '255' characters in the debug information
    c:\program files\microsoft visual studio\vc98\include\map(46) :
    see reference to class template instantiation
    'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,std::pair<std::basic_string<char,std::char_traits<

    char>,std::allocator<char> > const
    ,S>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<S> >::_Kfn,std::less<std::basic_st

    ring<char,std::char_traits<char>,std::allocator<char> >
    >,std::allocator<S> >' being compiled

    c:\text1.cpp(21) : see reference to class template
    instantiation
    'std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
    >,S,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator

    <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" <> wrote in message
    > news:...
    > > 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::string, S> m; /* 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
    Anamika, Oct 30, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Elliott
    Replies:
    4
    Views:
    1,133
    Simon Elliott
    Mar 10, 2005
  2. Peter Jansson
    Replies:
    5
    Views:
    6,253
    Ivan Vecerina
    Mar 17, 2005
  3. Vinu
    Replies:
    4
    Views:
    341
    Jim Langston
    Jul 7, 2005
  4. Vinu
    Replies:
    0
    Views:
    333
  5. Marcus
    Replies:
    2
    Views:
    572
    Marcus
    Dec 9, 2005
Loading...

Share This Page