Syntax

C++ Create a Map Syntax

In C++, create a map: creates sorted key-value pairs — std::map<std::string, int> ages; ages["Ada"] = 36;

Quick Answer

Syntax
std::map<std::string, int> ages; ages["Ada"] = 36;
C++Syntax

Create a Map

Code example
std::map<std::string, int> ages; ages["Ada"] = 36;

Creates sorted key-value pairs.

Learn More

How to create a map in C++

  1. Open your C++ file or editor.
  2. Copy the example, then replace its sample names and values for your code.

C++ Create a Map Syntax

Use std::map<std::string, int> ages; ages["Ada"] = 36;.

Related Syntax References

Frequently asked questions

What is the C++ syntax for create a map?

Use this pattern: std::map<std::string, int> ages; ages["Ada"] = 36;

Can I copy this C++ code example?

Yes. Use Copy code and adapt the example to your program.

Is this C++ syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify