求大神说明该如何修改这个错误~~~~~
我写的这个string Upper(string & s);函数是为了:将string对象的内容装换为大写,但是不知道该如何一个个地读取string字符串里的字符这个函数要求接受一个指向string对象的应用做为参数;
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
string Upper(string & s);
int main()
{
cout<<"Enter a string (q to quit): ";
string str;
getline(cin,str);
Upper(str);
while(str!="q")
{
cout<<"Next string (q to quit): ";
getline(cin,str);
Upper(str);
}
cout<<"Bye.\n";
return 0;
}
string Upper(string & s)
{
while(*s)
{
toupper(*s);
s++;
}
return s;
}










程序代码:
感谢,我把你给我的代码运行之后,出现了新问题是:输入字符串后要按两次才显示转换后的大写,我认为是getline()函数保留回车符,下一次读取会先读取回车符,我就在循环里加了一句cin.get();不过还是没能解决。