从大写变为小写C ++ [英] Change from uppercase to lowercase C++
本文介绍了从大写变为小写C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将输入从大写改为小写,例如。如果输入是R - 它更改为r。我想它与字符串不是char。我试过这个
I want to change the input from uppercase to lowercase, eg. if the input is R - it changes to r. I want it with string not char. I have tried this
one=tolower(one);
two=tolower(two);
但无效。
#include <cctype>
#include <iostream>
using namespace std;
int main () {
string one;
string two;
cout << "\nPlayer One, please enter your move: ('p' for Paper, 'r' for Rock, '$
cin >> one;
cout <<"\nPlayer Two, please enter your move: ('P' for Paper, 'R' for Rock, 'S'$
cin >> two;
推荐答案
您可以使用 std :: transform
右 std :: tolower
overload:
You can use std::transform
and the right std::tolower
overload:
#include <cctype> // std::tolower
#include <algorithm> // std::transform
std::transform(one.begin(), one.end(), one.begin(),
[](char c)
{ return std::tolower(static_cast<unsigned char>(c));});
这篇关于从大写变为小写C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文