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
Post a Comment