题目:
编写一个函数,它接受一个指向string对象的引用作为参数,并将该string对象的内容转换为大写。编写一个程序,它通过使用一个循环让您能够用不同的输入来测试这个函数
源代码:
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
void Print_upper(string& ch);
int main()
{
string ch;
cout << "请输入字符串(输入q退出): ";
while (getline(cin,ch))
{
if (ch[0] == 'q' && ch[1] == '\0')
break;
Print_upper(ch);
cout << ch << endl;
cout << "请输入字符串(输入q退出): ";
}
cout << "输入结束\n";
return 0;
}
void Print_upper(string& ch)
{
for (int i = 0; i < ch.size(); i++)
{
ch[i] = toupper(ch[i]);
}
}
演示效果:
如果朋友你感觉文章的内容对你有帮助,可以点赞,关注文章和专栏以及关注我哈,嘿嘿嘿我会定期更新文章的,谢谢朋友你的支持哈