酷代码 AI
菜单
服务商
DeepSeek字节豆包
更多选项

字符串全小写转换C++实现与样例

下面是一个C++实现,可以将输入的字符串中所有大写字母转换为小写字母: ```cpp #include <iostream> #include <string> #include <cctype> using namespace std; int main() { string input; getline(cin, input); // 读取整行字符串 string output; for (char ch : input) { output += tolower(ch); // 将每个字符转为小写 } cout << output << endl; return 0; } ``` ### 代码说明 - 使用 `getline(cin, input)` 读取一行字符串,支持包含空格的情况。 - 遍历字符串中的每个字符 `ch`。 - `tolower(ch)` 将大写字母转为小写,小写字母保持不变。 - 将转换后的字符逐个拼接到 `output` 字符串中。 - 最后输出全部小写的结果。 ### 示例 输入: ``` HelloWorldABC ``` 输出: ``` helloworldabc ``` ######[AI问答 | 225点数解答 | 2026-07-11 19:12:57]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]