1. 程式人生 > >C++中字串大小寫轉換

C++中字串大小寫轉換

字串大小寫轉換 

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

int main(){
	string str1="hersheyisunique!";
	string str2="ABCDEFGHIJKLMNO!";
	
	transform(str1.begin(),str1.end(),str1.begin(),::toupper);
	transform(str2.begin(),str2.end(),str2.begin(),::tolower);
	
	cout<<str1<<endl;
	cout<<str2<<endl;
	
	return 0;
}

執行結果:

HERSHEYISUNIQUE! abcdefghijklmno!