Search code examples
c++stringlowercase

Transformation to lower case in C++


#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include <string>   
#include <algorithm>

using namespace std;

string A,B;

int main()
{
    int t,l,i;
    scanf("%d",&t);
    while(t--)
    {
        std::string str;
        std::getline(cin, str);
        std::transform(str.begin(), str.end(), str.begin(), ::tolower);
        cout<<str;
        /*for(i=0;i<s.length();i++)
        {
            s[i]=toupper(s[i]);
        }*/
    }

    return 0;
}

i wrote this code to convert to lower case but when run on ideone with input

1
hola please!!!

it shows output no can u tell or correct it morever this will help me learn the use of std:lowercase function taking getline cin as input rather than considering it as array


Solution

  • The problem is definitely with the way you are reading in. scanf("%d",&t); doesn't consume the return character, so it is still there on the getline, which will get an empty sting. Change it to scanf("%d\r",&t).