C++字符串大小写之for语句

for语句

      • 语法形式
      • 两行语句转大写或者小写

语法形式

for (declaration : expressin)
{
     
    statement
}

declaration一般使用auto类型,无需考虑编译器的类型自动分配

两行语句转大写或者小写

使用引用标识符&

    string s = "what a summer day";
    for (auto& temp : s)
        temp = toupper(temp);
    cout << s << endl;
    for (auto& temp : s)
        temp = tolower(temp);
    cout << s << endl;

C++字符串大小写之for语句_第1张图片

你可能感兴趣的:(C++)