#include <iostream>
#include <string>
#include <cctype>
using namespace std;
string & up(string & st);
int main()
{
cout <<"Enter a string (q to quit): ";
string str;
while (getline(cin,str)&&str!="q")
{
cout <<up(str) <<endl;
cout <<"Next string (q to quit): ";
}
return 0;
}
string & up(string & st)
{
for (int i=0;i<sizeof st;i++)
st[i]=toupper(st[i]);
return st;
}
本文展示了一个简单的C++程序,该程序通过函数实现将用户输入的字符串转换为全大写的功能。使用了标准库中的字符转换函数,适用于初学者学习C++基本语法和字符串操作。
985

被折叠的 条评论
为什么被折叠?



