Map (c++ Container) Article Index for
Map
Website Links For
Map
 

Information About

Map (c++ Container)





USAGE

The map is declared in this format:

:map <''key_type'', ''value_type'' [, ''memory_allocatior'' ]> ''map_name''

The following code demonstrates how to use the map to store attendance records:

#include
#include
#include
#include
using namespace std;

int main() {
cout.setf(ios::boolalpha);
map present;
string s;
while (cin>>s && s!="end") present {Link without Title} = true;
while (cin>>s && s!="end") cout<{Link without Title} ;
return 0;
}

When executed, the user first types in each name which is present, and a word "end" at the end of input; then for each name queried, "true" would be printed if the person queried was present, and "false" if not.

The above example also demonstrates that if the content of a certain key value is not initialized, the default value of that type of variable is returned, for example 0 for a number, an empty string for a string, and the contructor default value for Structures and classes.


SEE ALSO