String 从给定字符串C++;11
在下面的代码中,我将尝试从给定字符串中删除特定字符String 从给定字符串C++;11,string,c++11,erase,String,C++11,Erase,在下面的代码中,我将尝试从给定字符串中删除特定字符 int main(void){ string query="a*de*da"; string org; uint8_t rmc='*'; std::vector<string::const_iterator> wpos; for(string::const_iterator itr = org.begin(); itr!=org.end(); ++itr){
int main(void){
string query="a*de*da";
string org;
uint8_t rmc='*';
std::vector<string::const_iterator> wpos;
for(string::const_iterator itr = org.begin();
itr!=org.end();
++itr){
if(*itr==rmc){
wpos.push_back(itr);
}
}
uint64_t wcnt=0;
for(auto witr: wpos){
org.erase( witr-(wcnt++) );
}
query=org;
return 0;
}
int main(无效){
string query=“a*de*da”;
字符串组织;
uint8_t rmc='*';
std::向量wpos;
for(string::const_迭代器itr=org.begin();
itr!=org.end();
++itr){
如果(*itr==rmc){
wpos。推回(itr);
}
}
uint64_t wcnt=0;
用于(自动witr:wpos){
org.erase(witr-(wcnt++);
}
查询=组织;
返回0;
}
在这段代码中,我希望query=“adeda”但是,我得到了一个错误
error: no matching function for call to ‘std::basic_string<char>::erase(__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >)’
org.erase(witr-wcnt);
错误:调用“std::basic\u string::erase(\uu gnu\u cxx::\uu normal\u迭代器)”时没有匹配的函数
org.erase(witr wcnt);
我的实验设置是CentOS6.7上devtoolset-3的g++4.9.2,从C++98到C++11,
std::string::erase的签名从
iterator erase(iterator p)
到
看起来g++4.9.2仍然使用旧版本。如果将string::const_iterator
更改为string::iterator
,则应编译示例
iterator erase(const_iterator p)