Hi everyone!

I am trying to understand tolower function... I don't get the locale variable to be honest and I would also like to know what I have to do so as to save the lower case string to another string and not just print it! That's my code...

#include <iostream>
#include <string>
#include <cctype>
#include <locale>
using namespace std;

int main()
{
        locale loc;
        int i,k,l;
        string str="Test String";
        for (i=0;i<str.length();i++)
                cout<<tolower(str[i],loc);
        cout<<endl;
        char tmp;
        for (k=0;k<str.size()-1;k++)
        {
                for (l=k+1;l<str.size();l++)
                {
                        if (str[k]>str[l])
                        {
                                tmp=str[k];
                                str[k]=str[l];
                                str[l]=tmp;
                        }
                }
        }
        cout<<str<<endl;
        return 0;
}

Thank you :)

I figured it out :) I was trying to save it to another string and I had some trouble with that but I just changed the existing string. These are the changes in my code:

int main()
{
        int i,k,l;
        string str="Test String";
        for (i=0;i<str.length();i++)
                str[i]=tolower(str[i]);
        cout<<str<<endl;
.
.
.
.
.      
}

Yup tolower return the 'lower' version of the argument passed if valid. IT does not change the argument to its lower-cased version

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.