By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

std::map operator[] and default values of build-in types

P: n/a
If new pair is inserted into std::map through operator[], is default value
for build-in types equal to 0?
eg.
std::map<std::string,bool> m;
bool b=m["not existing key"];
will b equal to false, or will it contain undefined value?
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Tue, 29 Mar 2005 11:15:22 +0200 in comp.lang.c++, "qfel"
<[q_tmp]@[aster.pl]> wrote,
If new pair is inserted into std::map through operator[], is default value
for build-in types equal to 0?
Yes.
eg.
std::map<std::string,bool> m;
bool b=m["not existing key"];
will b equal to false, or will it contain undefined value?


The std containers go to some effort to avoid undefined values.

Jul 23 '05 #2

P: n/a
In article <42*********************@mamut2.aster.pl>,
"qfel" <[q_tmp]@[aster.pl]> wrote:
If new pair is inserted into std::map through operator[], is default value
for build-in types equal to 0?
eg.
std::map<std::string,bool> m;
bool b=m["not existing key"];
will b equal to false, or will it contain undefined value?


b will be false.

-Howard
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.