Max frequency character

STRINGS-MAX FREQUENCY CHARACTER
Take as input S, a string. Write a function that returns the character with maximum frequency. Print the value returned.

Input Format:
a

Constraints:
A string of length between 1 to 1000.

Output Format
Character

Sample Input
aaabacb
Sample Output

a

#include
#include
#include<unordered_map>
#include
using namespace std;

char maxOcc(string s)
{

pair<char,int>x;
x.second=INT_MIN;
unordered_map<char,int>m;
for(int i=0;s[i]; i++)
m[s[i]]++;

for(auto curr:m)
{
if(curr.second>x.second)
x.first=curr.first;
x.second=curr.second;
}

return x.first;
}
int main() {
string S;

getline(cin,S);

cout<<maxOcc(S);
return 0;
}

for(auto curr:m)
{
if(curr.second>x.second)
x.first=curr.first;
x.second=curr.second;
}

The error is in this section in your code.

Rest the code is completely correct
It should be

for(auto curr:m)
{
if(curr.second>x.second)
{
x.first=curr.first;
x.second=curr.second;
}

}

You missed the braces of if
Hence it was executing the second statement after if everytime, which was not required.