c++ - How to manipulate a string to lower case and store in same variable -


i have piece of code asks user input, type "string" , simple process, want whatever user inputs converted using tolower() function. supposed do, can't seem assign same variable. please?

#include <locale> #include <string> #include <iostream> //maybe other headers, headers aren't problem, not going list them  while (ncommand == 0)         {               locale loc;             string scommand;             cin >> scommand;              (int = 0; < scommand.length(); ++i)             {             scommand = tolower(scommand[i],loc);             cout << scommand;             } 

for example if user types in scommand h

how want if user types in or or help

scommand should 'help' either way

you're assigning string character when want assign character stored @ position lower case version.

therefore change this:

scommand = tolower(scommand[i], loc); 

to this:

scommand[i] = tolower(scommand[i], loc); //      ^^^ 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -