一个C++的迭代器程序,求纠错。。。
程序如下:#include<iostream>usingnamespacestd;intcount();intmain(){inttimes;strings="Maryh...
程序如下:
#include<iostream>
using namespace std;
int count();int main()
{
int times;
string s = "Mary had a little lamb.";
times = count(s, 'a'); cout << times <<endl;
return 0;
}
int count(const string &s, char c){
int n = 0;
string::const_iterator i = find(s.begin(), s.end(), c);
while(i != s.end())
{
n++;
i = find(i + 1, s.end(), c);
}
return n;
}
编译器提示“ string::const_iterator i = find(s.begin(), s.end(), c);“这句有错,该怎么改??还有那个const_iterator怎么用???求大神指导。。
谢谢啦!! 展开
#include<iostream>
using namespace std;
int count();int main()
{
int times;
string s = "Mary had a little lamb.";
times = count(s, 'a'); cout << times <<endl;
return 0;
}
int count(const string &s, char c){
int n = 0;
string::const_iterator i = find(s.begin(), s.end(), c);
while(i != s.end())
{
n++;
i = find(i + 1, s.end(), c);
}
return n;
}
编译器提示“ string::const_iterator i = find(s.begin(), s.end(), c);“这句有错,该怎么改??还有那个const_iterator怎么用???求大神指导。。
谢谢啦!! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询