devxlogo

Initialize STL Containers with Predefined Values

Initialize STL Containers with Predefined Values

This task is quite common task. However, explicit insertion of values can be unacceptable in many cases?like if you need to insert a lot of values.

I’ve found that it’s quite handy to use arrays for this task:

 pair arr[] ={   pair("640x480", 0),   pair("800x600", 1),   pair("1024x800", 2),   pair("1280x1024", 3)};map msi(arr, arr + sizeof(arr)/sizeof(arr[0]));

This technique is easily applied to vectors, sets, etc.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist