有一行字符,要求将每个单词中的第一个字母改成大写字母

代码示例:

#include<iostream>
#include<string>
using namespace std;
void main()
{
    string str[]={"hello","world","what","is","your","name"};
    int i,j;
    cout<<"源字符串为:"<<endl;
    for(i=0;i<6;i++)
        cout<<str[i]<<'\t';
        cout<<endl;
    for(i=0;i<6;i++)
        for(j=0;str[i][j]!='\0';j++)
        {
            if(str[i][0]>='a'&&str[i][0]<='z')
                str[i][0]-=32;
        }
        for(i=0;i<6;i++)
            cout<<str[i]<<'\t';
        cout<<endl;
}

运行结果:

posted @ 2012-06-28 20:38  iamvirus  阅读(2250)  评论(0编辑  收藏  举报