Using C++11:
#include <map> using namespace std; map<int, char> m = {{1, 'a'}, {3, 'b'}, {5, 'c'}, {7, 'd'}};
Using Boost.Assign:
#include <map> #include "boost/assign.hpp" using namespace std; using namespace boost::assign; map<int, char> m = map_list_of (1, 'a') (3, 'b') (5, 'c') (7, 'd');
Related Posts:
- C++ Double Address Operator? (&&)
- How to remove all the occurrences of a char in c++ string
- How to sum up elements of a C++ vector?
- What is the easiest way to initialize a std::vector with hardcoded elements?
- How do I erase an element from std::vector<> by index?
- Is it more efficient to copy a vector by reserving and copying, or by creating and swapping? [duplicate]
- How do I reverse a C++ vector?
- A proper way to create a matrix in c++
- A proper way to create a matrix in c++
- Why does the C++ STL not provide any “tree” containers?
- How to iterate through a list of objects in C++?
- push_back vs emplace_back
- How to find if a given key exists in a C++ std::map
- Parsing a comma-delimited std::string
- How to ensure that a std::map is ordered?
- What is the difference between set and hashset in C++ STL?
- push_back vs emplace_back
- Remove spaces from std::string in C++
- What is the difference between const_iterator and non-const iterator in the C++ STL?
- Remove spaces from std::string in C++
- How to check that an element is in a std::set?
- What’s the most efficient way to erase duplicates and sort a vector?
- Best way to extract a subvector from a vector?
- Implementation of Vector in C++
- Appending a vector to a vector
- Determine if map contains a value for a key?
- C++ Erase vector element by value rather than by position?
- How to get current time in milliseconds?
- Use the auto keyword in C++ STL
- std::string length() and size() member functions
- sorting in std::map where key is a std::string
- How to do std::string indexof in C++ that returns index of matching string?
- Why can’t I make a vector of references?
- C++ equivalent of StringBuffer/StringBuilder?
- Displaying contents of a vector container in C++
- List iterator not dereferencable?
- How to create a dynamic array of integers
- How to implement 2D vector array?
- What is the difference between g++ and gcc?
- What is the best way to use a HashMap in C++?
- What is the difference between float and double?
- How do I find the length of an array?
- C++ — expected primary-expression before ‘ ‘
- Using getline() with file input in C++
- What are the rules of the std::cin object in C++?
- ‘g++’ is not recognized as an internal or external command, operable program or batch file
- How do I convert a double into a string in C++?
- How to create timer events using C++ 11?
- How to concatenate two strings in C++?
- ‘g++’ is not recognized as an internal or external command, operable program or batch file
- Read file line by line using ifstream in C++
- Virtual/pure virtual explained
- error: redefinition of class
- Officially, what is typename for?
- Is there a maxheap in the C++ standard library?
- How do I iterate over the words of a string?
- How to declare a global variable in C++
- Why doesn’t C++ have a garbage collector?
- How does ifstream’s eof() work?
- In C++, what is wx.h?
- terminate called after throwing an instance of ‘std::invalid_argument’ what(): stoi
- How to find memory leak in a C++ code/project?
- Error: C++ requires a type specifier for all declarations
- invalid use of non-static member function
- cin >> “no operator matches these operands”
- C++ on mac : linker command failed with exit code 1 (use -v to see invocation)
- Correct way to use cin.fail()
- Destructor for a linked List
- Why use a new call with a C++ ‘vector’?
- When should I use the new keyword in C++?
- Identifier is undefined
- What are the most widely used C++ vector/matrix math/linear algebra libraries, and their cost and benefit tradeoffs?
- Delete 2D array C++
- class not declared in scope – even though .h was included
- Best C/C++ Network Library
- declaring a priority_queue in c++ with a custom comparator
- How do malloc() and free() work?
- Call to implicitly deleted copy constructor in LLVM
- C++ Linked List Node with class
- prototype for “….” does not match any in class “…”
- Cannot open Windows.h in Microsoft Visual Studio
- Nested For – Loops to create multiplication table C++
- The system cannot find the file specified. in Visual Studio
- bit vectors in c++
- to_string not declared in scope
- GCC -fPIC option
- initialize a vector to zeros C++/C++11
- When to use “new” and when not to, in C++?
- too many initializers for ‘int [0]’ c++
- function does not take 1 arguments c++
- overloaded function with no contextual type information
- How exactly do lookup tables work and how to implement them?
- Vector declaration “expected parameter declarator”
- C++ Destructors with Vectors, Pointers,
- error C2065: ‘cout’ : undeclared identifier
- How to get the MD5 hash of a file in C++?
- Where can I find ‘winmm.lib’ (I’m using Visual Studio 2012)
- What is a `char*`?
- Does static constexpr variable inside a function make sense?
- “Incomplete type not allowed ” when creating std::ofstream objects