Making std::map::find Function Case Sensitive in C++ | Case Sensitive Search Using the map in C++

  • C++
  • 1 min read

This C++ tutorial shows how to make the std::map::find function case sensitive.

Case Sensitive Search Using the map in C++ Example

The below example will look for the "FOX" string in uppercase using the map function and, if found, then will print on the console:

#include <iostream>
#include <map>



using namespace std;

int main()
{
    map<string, int> mp;
    mp["fox"] = 1;
    mp["Fox"] = 2;
    mp["FOX"] = 3;
    mp["foX"] = 4;    

    auto it = mp.find("FOX");
    if (it != mp.end())
       std::cout << it->first << " " << it->second << std::endl;

    return 0;
}

 

Output:

FOX 3