Thread: Iterator and tolower problem

  1. #1
    Registered User
    Join Date
    Nov 2013
    Location
    Norway
    Posts
    40

    Iterator and tolower problem

    (Noob question)
    I am trying to write a function that takes a string and converts every character to lowercase. Problem is, it doesnt...

    I am able to compile the program and run it, but the program doesnt turn the string I input into lowercase.

    Here is the function:

    Code:
    void toLow(string &s){
        for (auto i = s.begin(); i != s.end(); i++)
        {
            tolower(*i);
    
    
        }
    }
    I have tried using a temporary char to be a middleman in the conversion (I am basically trying anything on the top of my head, because I dont understand the problem, or atleast, I cant see it..) but, without luck.

    I dont NEED an example, just someone to point out the error in the code and a point in the right direction. It is probably just a derp error... (I have a lot of them)

  2. #2
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    *i = tolower(*i)?

  3. #3
    Registered User
    Join Date
    Nov 2013
    Location
    Norway
    Posts
    40
    AS I SAID... derp error.. omg >.< #fml

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    void ToLow(string& s)
    {
        for (auto & c : s)
            c = tolower(c);
    }
    ...or...
    Code:
    void ToLow(string& s)
    {
        std::transform(s.begin(), s.end(), s.begin(), &tolower);
    }
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Palindrome code (problem with tolower)
    By CsdJohn in forum C Programming
    Replies: 3
    Last Post: 12-01-2013, 08:17 AM
  2. toupper() & tolower() problem?
    By saqib_ in forum C++ Programming
    Replies: 35
    Last Post: 12-04-2009, 11:45 AM
  3. Connecting input iterator to output iterator
    By QuestionC in forum C++ Programming
    Replies: 2
    Last Post: 04-10-2007, 02:18 AM
  4. tolower function problem
    By Jack-Bauer in forum C++ Programming
    Replies: 6
    Last Post: 05-18-2006, 11:17 PM
  5. iterator problem
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 03-23-2002, 02:26 PM