在C++中用STL转换整个字符串到大写或小写

给定一个字符串,将整个字符串转换为大写或小写,使用C++中的STL。

null

例如:

For uppercase conversion
Input : s = "String"
Output : s = "STRING"

For lowercase conversion
Input : s = "String"
Output : s = "string"

使用的功能: 使改变 :对给定的数组/字符串执行转换。 图珀(int c): 返回字符c的大写版本。如果c已经是大写,则返回c本身。 托洛尔(int c): 返回字符c的小写版本。如果c已经是小写,则返回c本身。

// C++ program to convert whole string to
// uppercase or lowercase using STL.
#include<bits/stdc++.h>
using namespace std;
int main()
{
// su is the string which is converted to uppercase
string su = "Jatin Goyal" ;
// using transform() function and ::toupper in STL
transform(su.begin(), su.end(), su.begin(), :: toupper );
cout << su << endl;
// sl is the string which is converted to lowercase
string sl = "Jatin Goyal" ;
// using transform() function and ::tolower in STL
transform(sl.begin(), sl.end(), sl.begin(), :: tolower );
cout << sl << endl;
return 0;
}


输出:

JATIN GOYAL
jatin goyal

本文由 贾丁·戈亚尔 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。

如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享