怎样将string对象的内容转换为大写

2025-05-13 00:43:35
推荐回答(1个)
回答(1):

参考代码如下:

#include 
#include 
using namespace std;

void small_to_big(string &s);
int main()
{
string str;
cout<<"Enter a string (q to quit): ";
getline(cin,str);
while(str!="q")
{
small_to_big(str);
cout<cout<<"Next string (q to quit): ";
getline(cin,str);
}
cout<<"Bye."<return 0;
}
void small_to_big(string &s)
{
for(int i=0;i!=s.size();i++)
s[i]=toupper(s[i]);
}