C++ map operator=() functionThere are following three uses of operator=() in a map:
Syntaxcopy (1):- Copies all the elements from x into the map container. move (2):- Moves the contents of x into the map container. initializer_list (3):- Copies the elements of il into the map container. Parameterx: A map object with the same type. il: An initializer list object. Return valuethis pointer. Example 1Let's see a simple example to copy the content of one map to another. Output: Map m1 contains following elements a = 10 b = 20 c = 30 After copying the elements from m1 to m2... Map m2 contains following elements a = 10 b = 20 c = 30 In the above example, operator=() function is used to copy the content of one map m1 to another map m2. Example 2Let's see a simple example to move the elements of one map to another. Output: Map m1 contains following elements a = 1 b = 2 c = 3 After moving the elements from m1 to m2... Map m2 contains following elements a = 1 b = 2 c = 3 In the above example, operator=() function is used to move the content of one map m1 to another map m2. Example 3Let's see a simple example to copy the content from the initializer list to map. Output: Map contains the following elements a = 100 b = 200 c = 300 d = 400 In the above example, operator=() is used to copy the content from initializer list to map m. Example 4Let's see a simple example. Output: Size of first: 0 Size of second: 3 In the above example, first it will calculate the size of the empty map fisrt then add some elements to the first map and copy to second map. Next TopicC++ Map |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India