下面的程序是对于给定的字符串,将其首字母变为大写。
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

string toUpper(string &s)
{
string rst;
string firstChar=s.substr(0,1);
transform (firstChar.begin(), firstChar.end(), firstChar.begin(), (int(*)(int))toupper);
rst=firstChar+s.substr(1);
return rst;

}
int main(void)
{
string s;
cin>>s;
string rst=toUpper(s);
cout<<rst<<endl;
return 0;
}























若变为小写,则需将 toupper 变为 tolower.