【发布时间】:2019-10-06 09:20:30
【问题描述】:
我正在解决一个将字符串中的字符转换为小写的非常简单的问题,我显然使用了tolower()。但是,我看到有人使用它,这是一个公认的解决方案。
这是 cpp 中 tolower() 函数的替代方法吗?如果是,为什么?
问题参考:https://atcoder.jp/contests/abc126/tasks/abc126_a
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
// We want to convert "ABC" to "aBC"
string S = "ABC";
S[0] += 0x20;
// Returns "aBC"
cout << S << endl;
return 0;
}
【问题讨论】:
-
查看 Rahul Sharma 关于其工作原理的回答:stackoverflow.com/a/38707004/11087678