C++ STL::Maps::insert()














































C++ STL::Maps::insert()



INTRODUCTION:
  •  In this article you will come to know about how to use the insert() function of map.  
  • The insert() function basically inserts elements with a particular key in the map container. 
  • The syntax is as follows: 
Name_of_map.insert({key,element}).
 C++ Code:
#include <iostream>
#include<map> using namespace std; int main() { map<int, string> m; m.insert({ 2, "Mango" }); m.insert({ 1, "Apple" }); m.insert({ 3, "Orange" }); // prints all elements map<int, string>::iterator it; cout << "KEY\tFruits\n"; for (it = m.begin(); it != m.end(); ++it) { cout << it->first << '\t' << it->second << '\n'; } return 0; }

OUTPUT:


More Articles of Shreyas Mandlik:

Name Views Likes
C++::STL::List::crbegin() 348 0
C++::STL::List::cend() 326 0
C++::STL::List::cbegin() 343 0
C++::STL::List::rend() 350 0
C++::STL::List::rbegin() 357 0
C++::STL::List::max_size() 364 0
C++::STL::List::emplace_back() 359 0
C++::STL::List::emplace_front() 360 0
C++::STL::List::Clear() 332 0
C++::STL::List::operator= 320 0
C++::STL::List::Swap() 286 0
C++::STL::List::splice() 371 0
C++::STL::List::Merge() 260 0
C++::STL::List::emplace() 350 0
C++::STL::List::reverse() 310 0
C++::STL::List::sort() 311 0
C++::STL::List::resize() 320 0
C++::STL::List::size() 352 0
C++ STL::List::remove() 316 0
C++ STL::List::assign() 400 0
C++ STL::List::erase() 424 0
C++ STL::List empty() 337 0
C++ STL ::List begin() and end() 250 0
C++ STL::List ::pop_back() 283 0
C++ STL:: List::pop_front() 341 0
C++ STL :: List :: push_back() 348 0
C++ STL::List::push_front() 288 0
C++ STL::List back() 356 0
C++ STL::List front() 271 0
C++ STL:: Maps::"operator[]" 277 0
C++ STL::Map::emplace_hint() 315 0
C++ Binary Trees::Traversals 336 0
C++ STL ::Map::cend() 315 1
C++ STL:: Map::cbegin() 289 0
C++ STL::Map crend() 314 0
C++ STL:: Map::crbegin() 320 0
C++ STL::Map::"operator=" 323 0
C++ STL::Map::Lower_bound() 444 0
C++ STL :: Map:: Upper_bound() 374 0
C++ STL:: Map emplace() 321 0
C++ STL ::Map::rend() 343 0
C++ STL:: Map::rbegin() 276 0
C++ STL::Maps::insert() 397 0
C++ STL::Map::Clear() 395 0
C++ STL::Map erase() 359 0
C++ STL::Map count() 374 0
C++ STL::Map empty() 411 0
C++ STL::Map max_size() 302 0
C++ STL::Map size() 362 0
Program on Implementation of Map. 376 1

Comments