指针 输入1行文字,将其中大写字母转为小写字母,并将其中非字母、非数字字符一律改写为下划线符号‘_’。

输入1行文字,将其中大写字母转为小写字母,并将其中非字母、非数字字符一律改写为下划线符号‘_’。

img


#include <iostream>
#include <algorithm>

using namespace std;

int main() {
        cout << "input: ";
        string str;
        cin >> str;
        ///转小写
        transform(str.begin(),str.end(),str.begin(),[](const char& ch){
                        if (::isalpha(ch)) return ::tolower(ch);
                        else return (int)'_';
                        });
        cout<< "output: " << str << endl;
        return 0;
}


手打不易,如果有关注,不妨点个关注啊