doubt string/map c++

Asked

Viewed 99 times

0

Good afternoon! I’m answering a programming list, the question is very easy and I know the logic of execution but there is a part that I do not know how to implement, I left it in italic.

Make a program that reads any text file and save each read string in a map that relates the word to its size. Do not distinguish between upper and lower case. Show all words and their respective sizes at the end of the program .

Is there any way to distinguish between upper and lower case letters in string comparisons in c++?

  • 1

    Use the tolower (or toupper) function on each of the characters being compared. You can also use the strcasecmp function of <strings. h>.

2 answers

2

Convert strings to minuscule.

#include <stdio.h>
#include <ctype.h>
int main ()
{
  int i=0;
  char str[]="Test String.\n";
  char c;
  while (str[i])
  {
    c=str[i];
    putchar (tolower(c));
    i++;
  }
  return 0;
}

1


#include <iostream>
#include <algorithm>
int main()
{
   std::string s{"Test string"};
   std::transform(s.begin(), s.end(), s.begin(), ::tolower);
   std::cout << s << std::endl;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.