#include#include using namespace std; int main() { string s1("juice and rice");//迭代模式 for(decltype(s1.size()) index=0;index !=s1.size() && !isspace(s1[index]); ++index)//没到数组最后一个,且不是空格 s1[index]=toupper(s1[index]); cout< 代码简略分析:
只要index的值不超过s1.size(),它便可以一直执行下去,在遇到第一空格之后中断,也就完成第一个单词大写的任务



