I am counting the number of times every word occurs in a text file. I would like to avoid cases and hence am doing tolower to my input and then counting. I have a map data struc
This should work. For multiple cases the first case will be inside the map and not lower case. Also the solution uses only one map as you wanted
using namespace std;
struct StrCaseInsensitive
{
bool operator() (const string& left , const string& right )
{
return _stricmp( left.c_str() , right.c_str() ) < 0;
}
};
int main(void)
{
char* input[] = { "Foo" , "bar" , "Bar" , "FOO" };
std::map CountMap;
for( int i = 0 ; i < 4; ++i )
{
CountMap[ input[i] ] += 1;
}
return 0;
}