代码示例:
#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; }
运行结果: