Search code examples
c++stringtolower

C++ Make Lower Function


I wrote a simple function in c++ to turn a string in to all lower case letters using chars and iterating through each char in the string. Can someone please explain why when I run this program in the console window, I get an output in addition to my original input if the function never references cout.

#include <iostream>
#include <cctype>
#include <cstdlib>
using namespace std;
string makelower(string text)
{
    int iter = 0;
    char cha;
    string newtext;
    while (iter < text.length())
    {
        cha = text[iter];
        cha = tolower(cha);
        newtext+=cha;
        iter++;
    }
    return(newtext);
}

int main()
{
    string a;
    cin>>a;
    a = makelower(a);
    cout<<a;
}

Solution

  • putchar writes a character out to stdout http://www.cplusplus.com/reference/cstdio/putchar/