首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

这个函数的有关问题出在哪

2012-03-25 
这个函数的问题出在哪?stringexchange(string&s){for(vector string ::iteratorixname_bitch.begin()i

这个函数的问题出在哪?
string   exchange(string   &s)
{
for(vector <string> ::iterator   ix   =   name_bitch.begin();   ix   !=   name_bitch.end();   ++   ix)
{
string   temp   =   (*ix);
const   string   kobe   =   "a ";                                                                                                                                                                                                                                                                                                                                      
s.replace((s.find(temp)   -   temp.size()   +   1),s.find(temp),kobe);
}
for(vector <string> ::iterator   ix   =   number_bitch.begin();   ix   !=   number_bitch.end();   ++   ix)
{
string   temp   =   (*ix);
const   string   kobe   =   "a ";
s.replace((s.find(temp)   -   temp.size()   +   1),s.find(temp),kobe);
}
for(vector <string> ::iterator   ix   =   alphabet_bitch.begin();   ix   !=   alphabet_bitch.end();   ++ix)
{
string   temp   =   (*ix);
if((s.find(temp)   <   s.size())&&(temp   !=   "&& ")&&(temp   !=   "|| ")&&(temp   !=   "! "))
{
if(temp.size()   >   1)
s.erase(   (s.find(temp)   -   1)   ,   3   );
else   s.erase(   (s.find(temp)   -   1)   ,   2   );
}
else
s.erase(s.find(temp),1);
}
while(s.find( "() ")   <   s.size())
{
s.erase(s.find( "() ")   -   1,2);
}
s   =   "( "   +   s;
s   =   s   +   ") ";
                  return   s;
}

VS2005下提示说:有地方out_of_range..
谢谢

[解决办法]
s.replace((s.find(temp) - temp.size() + 1),s.find(temp),kobe);

如果向量里的元素temp不是s的子串,明显是会出错的
[解决办法]
随便问一句搂住,用VSS2005编C++爽吗?我还停留在VC6.0呢

[解决办法]
越界 ······

逻辑问题啊 ~
[解决办法]
s.erase( (s.find(temp) - 1) , 3 );
-----------------------------------
你的erase可能有问题吧,
s.find(temp) - 1最终的类型也会是itrerator


但3这个地址怎么有可以正确呢?删除 0xFFccdfee到3的范围你觉得有可能吗?

s.erase( (s.find(temp) - 1) , s.find(temp) + 2 );

[解决办法]
逻辑上有问题.

热点排行