string类出现out of range 求帮助,如何改正
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
void toup(string &str);
int main()
{
string str;
getline(cin,str);
while(str!="q")
{
toup(str);
cout<<str<<endl;
cout<<"Next string (q to quit):\n";
getline(cin,str);
}
system("pause");
return 0;
}
void toup(string &str)
{
cout<<str.size()<<"lenght.....";
int i=0;
while(str[i])
{
if(islower(str[i]))
str[i]=toupper(str[i]);
i++;
}
}
程序编译无错误,执行的时候,输入str后会出现out of range错误,求指导问题出在哪里?应该如何改正?