#include<iostream>
#include<string>
#include<cctype>
using namespace std;
string replace(string & );
int main()
{
string word;
cout << "Enter a string(q to quit):";
getline(cin,word);
while (word != "q")
{
string &input = word;
string lower=replace(input);
cout << lower << endl;
cout << "Enter a string(q to quit):";
getline(cin, word);
}
return 0;
}
string replace(string &a)
{
int size = a.size(); //这里也可以写成int size=a.length();关于字符串长度strlen()用于插入*;str.size()和str.length()用于string
for (int i = 0; i < size; i++)
{
a[i] = toupper(a[i]); //这里toupper()对string中的每个字符逐个进行大写变换,而我刚开始以为对整个字符串一下子转换完成,总是运行不出来
}
return a;
}
#include<string>
#include<cctype>
using namespace std;
string replace(string & );
int main()
{
string word;
cout << "Enter a string(q to quit):";
getline(cin,word);
while (word != "q")
{
string &input = word;
string lower=replace(input);
cout << lower << endl;
cout << "Enter a string(q to quit):";
getline(cin, word);
}
return 0;
}
string replace(string &a)
{
int size = a.size(); //这里也可以写成int size=a.length();关于字符串长度strlen()用于插入*;str.size()和str.length()用于string
for (int i = 0; i < size; i++)
{
a[i] = toupper(a[i]); //这里toupper()对string中的每个字符逐个进行大写变换,而我刚开始以为对整个字符串一下子转换完成,总是运行不出来
}
return a;
}