I see some things that may help you improve your code.
bool is not int
The bool type is a full-fledged first class type in C++. If I were an interviewer reading this code, I'd be perplexed:
bool res = areAnagrams(str1, str2);
if (res == 1)
{
std::cout << "Strings are anagram\n";
}
else
{
std::cout << "Strings are not anagram\n";
}
A similar thing is being done here:
if (str1.compare(str2) == 0)
{
return true;
}
else
{
return false;
}
First, we are comparing a bool to 1 (an int) which is odd enough. Next, if we're returning the result of the comparison, why don't we return the result of the comparison?
return !str1.compare(str2);
Better still:
return str1 == str2;
Understand references
The prototype of the toLower function is this:
std::string toLower(std::string str);
bool areAnagrams(std::string& str1, std::string& str2);
So reading this, the toLower makes a copy of its argument and areAnagrams uses references. However, the first few lines of the latter function are these:
str1 = toLower(str1);
str2 = toLower(str2);
There's little point to making copies and then assigning the copy back to the original. What I would recommend instead is to have toLower take a reference and areAnagrams pass by value. That way, we have a much more logical interface in which toLower modifies the passed string but areAnagrams does not.
Use auto to simplify code
The better choice for res in main would be to declare it auto instead of explicitly naming bool.
Consider the use of locale
Rather than writing your own toLower, why not use the one in <locale>? Here's how that might look:
auto& facet{std::use_facet<std::ctype<char>>(std::locale())};
facet.tolower(&str1.front(), &str1.back());
facet.tolower(&str2.front(), &str2.back());
Use better naming
The function toLower is a good name because (with the suggested change mentioned above) it says what it actually does. However, res is not a good name and it's not necessary to have a separate variable anyway. Instead of this strange construction:
bool res = areAnagrams(str1, str2);
if (res == 1)
{
std::cout << "Strings are anagram\n";
}
else
{
std::cout << "Strings are not anagram\n";
}
I would probably instead have written this:
std::cout << "Strings " << (areAnagrams(str1, str2) ? "are" : "are not")
<< " anagrams\n";
Although, as @TobySpeight points out in a comment, better for the purposes of translating the string into another language would be to keep the strings intact. One way to do that:
std::cout << (areAnagrams(str1, str2) ? "Strings are anagrams\n"
: "Strings are not anagrams\n");
Declare variables each on a separate line
Clarify variable declaration by declaring each one on a single line. See Guideline ES.10
Consider namespace or static
During an interview, I'd probably ask why you chose not to encapsulate the functions in a namespace, and why the functions are not static. There are arguments both ways for each of those; be aware of what they are and be able to explain and defend your choices.