#include <iostream>
#include <string>
#include <algorithm>
using std::cout;
using std::endl;
void main()
{
std::string str;
str.assign("Hello World!");
std::transform(str.begin(),str.end(),str.begin(),tolower); // or 'toupper'.
cout<<str.c_str()<<endl;
}
本文展示了一个使用C++进行字符串转换的例子,包括如何将字符串全部转换为小写。通过使用标准库中的<algorithm>和<string>,以及std::transform函数,实现了对HelloWorld!字符串的大小写转换。

2218

被折叠的 条评论
为什么被折叠?



