C++string大小写转换

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    string str = "ancdANDG";
    cout << "转换前的字符串: " << str << endl;
    
    for(auto &i : str){
        i = toupper(i);//i = tolower(i);
    }    
    cout << "转换后的字符串: " << str << endl;
    
    //或者
    for(int i = 0;i < str.size();++i){
		str[i] = toupper(s[i]);//str[i] = toupper(s[i]);
	}
	cout << "转换后的字符串: " << str << endl;
	
	return 0;
}
posted @ 2023-02-28 20:31  Travelever  阅读(30)  评论(0)    收藏  举报