473,805 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?????? ??

Oct 27 '06 #1
8 1895
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 ;
Oct 27 '06 #2

"Anamika" <sh************ *@gmail.comwrot e in message
news:11******** **************@ 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:

www.josuttis.com/libbook

-Mike
Oct 27 '06 #3
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" <sh************ *@gmail.comwrot e in message
news:11******** **************@ 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:

www.josuttis.com/libbook

-Mike
Oct 28 '06 #4

"Anamika" <sh************ *@gmail.comwrot e in message
news:11******** *************@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


Oct 28 '06 #5
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" <sh************ *@gmail.comwrot e in message
news:11******** *************@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
Oct 29 '06 #6

"Anamika" <sh************ *@gmail.comwrot e in message
news:11******** **************@ 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
Oct 29 '06 #7
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" <sh************ *@gmail.comwrot e in message
news:11******** **************@ 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
Oct 30 '06 #8
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" <sh************ *@gmail.comwrot e in message
news:11******** **************@ 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
Oct 30 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1601
by: Mike - EMAIL IGNORED | last post by:
I am looking for software that would translate xml strings to and from nested std:maps. Any suggestions? Thanks in advance. Mike.
2
2339
by: ash | last post by:
Hi, I'm getting started with STL, and am stuck at creating a map container. I checked one of the texts and found a code in there. To make it simple, i wrote the following: #include <iostream.h> #include <string.h> #include <map>
4
1518
by: Simon Elliott | last post by:
Here's a small example which uses std::maps within std::maps. Note the line flagged // *** copy? #include <iostream> #include <map> #include <string> struct Tfoo { Tfoo():i1_(0),i2_(0){}
1
2037
by: Jim Tarrant | last post by:
Hi, When I run our application under PurifyPlus, I get lots of "UMR: Uninitialized memory read" warnings, e.g. UMR: Uninitialized memory read in std::_Tree_nod<class std::_Tmap_traits<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class CTCSystem *,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct...
2
1918
by: Gernot Frisch | last post by:
Hi, I know I can give a std::map a sorting function in the c'tor. However, I would need to _change_ the sorting behaviour of an existing instance. How would I do that? Thank you, --
5
1785
by: DrLex | last post by:
This is a really annoying thing to look up in Google because all pages that mention STL maps or vectors will most likely also contain the word "template". So maybe this question has been asked before, but it's nearly impossible to find. I'm having trouble using STL vectors, maps, ... in templated functions, when the templated class is a template parameter of the map too. Below is a (cannibalized) example of a class 'Model' which contains...
5
1892
by: pallav | last post by:
I have a map like this: typedef boost::shared_ptr<NodeNodePtr; typedef std::vector<NodePtrNodeVecPtr; typedef std::map<std::string, NodePtrNodeMap; typedef std::map<std:string, NodePtr>::iterator NodeMapItr; NodeMap nmap; In my classes, I often find myself copying the second arguments of
3
6473
by: jacek.dziedzic | last post by:
Hi! What is the canonical way of finding an intersection of two std::maps? i.e. I have std::map<whatever,size_tmap1; std::map<whatever,size_tmap2; .... and I need an std::vector containing all the values that occur
6
1962
by: Hicham Mouline | last post by:
Hello, I am attempting to design a class: class C { std::map<double, const Ama; std::map<double, const Bma; ..
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10369
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.