Tangible Software Solutions

The Most Trusted Name in Source Code Conversion

C++ Equivalent to C# Dictionary

The nearly exact C++ equivalent to .NET's List collection is the std::unordered_map collection.

Original C#:

void Dictionaries()
    Dictionary<string, int> myDictionary = new Dictionary<string, int>();
    string s = "test";
    myDictionary.Add(s, 1);
    int i = myDictionary[s];
    i = myDictionary.Count;
    bool b = myDictionary.Count == 0;

Equivalent C++:

#include <string>
#include <unordered_map>

void Dictionaries()
    std::unordered_map<std::wstring, int> myDictionary;
    std::wstring s = L"test";
    myDictionary.emplace(s, 1);
    int i = myDictionary[s];
    i = myDictionary.size();
    bool b = myDictionary.empty();

If you need to convert from C# to C++ and you are depending on the results being reliable and accurate, then you will want to have C# to C++ Converter, the best C# to C++ converter, at your fingertips.

Copyright © 1997 - 2017 Tangible Software Solutions Inc.