string转化大小写(C++)

来源:互联网 发布:pos机s90如何设置网络 编辑:程序博客网 时间:2024/06/04 19:42

C++
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
using namespace std;
int main() {
    string s = "Clare";
    // toUpper
    transform(s.begin(), s.end(), s.begin(), toupper);
    // toLower
    //transform(s.begin(),s.end(),s.begin(),tolower);
    cout << s << endl;
}

 

C
#include <stdio.h>
#include <ctype.h>
int main() {
    char s[] = "Clare";
    int i = -1;
    while(s[i++]) 
        s[i] = toupper(s[i]);
    // s[i] = tolower(s[i]);
    puts(s);  
}

0 0