Changing a capital letter (read from cin) to lower case?

前端 未结 5 2036
独厮守ぢ
独厮守ぢ 2021-01-29 08:13

i wanna change the capital cin to lower case for the input , for example if cin>> one one=R it should be r so it convert it automatically

<
5条回答
  •  耶瑟儿~
    2021-01-29 08:40

    Try:

    #include 
    
    tolower(char)
    

    For a string input, you'll have to convert character by character:

    char str[]="ONE TWO\n";
    char c;
    int i=0;
    while (str[i])
    {
      c=str[i];
      str[i] = (char) tolower(c);  //I think it return an int, which you need to typecast to a char
      i++;
    }
    

提交回复
热议问题