本文介绍了更改大写字母(从cin读取)到小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  #include< cctype> 
#include< iostream>

using namespace std;
int main()
{
string one;
string two;
cout<< \ nPlayer One,请输入您的移动:('p'表示纸张,'r'表示岩石,'$
cin>>一个;

cout< \ nPlayer Two,请输入您的移动:('P'表示纸张,'R'表示岩石,'S'表示$
cin表示两个;


解决方案

您可以使用transform编写代码:



<$一个,请输入您的移动:('p'表示纸张,'r'表示纸张,对于Rock,'< cin>> one;

std :: transform(one.begin(),one.end one.begin(),:: tolower);
cout< Player二,请输入您的移动:('P'表示纸,'R'表示摇滚,'S'& < std :: endl;
cin>> two;
std :: transform(two.begin(),two.end(),two.begin(),:: tolower);
std :: cout<<one =<

输出可能如下(对于R,P):

 玩家一,请输入您的行动:('p'表示纸,'r'表示摇滚,'
R

玩家二,请输入你的移动:('P'为纸,'R'为摇滚,'S'
P
one = r; two = p


    #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;
解决方案

You can write your code using transform:

string one;
string two;
cout << "\nPlayer One, please enter your move: ('p'  for Paper, 'r' for Rock, '" << std::endl;
cin >> one;

std::transform(one.begin(), one.end(), one.begin(), ::tolower);
cout <<"\nPlayer Two, please enter your move: ('P' for Paper, 'R' for Rock, 'S'" << std::endl;
cin >> two;
std::transform(two.begin(), two.end(), two.begin(), ::tolower);
std::cout << "one=" << one << " ; two=" << two << std::endl;

The output may be as follows (for R, P):

Player One, please enter your move: ('p'  for Paper, 'r' for Rock, '
R

Player Two, please enter your move: ('P' for Paper, 'R' for Rock, 'S'
P
one=r ; two=p

这篇关于更改大写字母(从cin读取)到小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 17:12