string.replace help

M

MCH

Hi there,
I am using std:string and try to replace a substring with replace
function. From the document, I found one prototype of string.replace

basic_string& replace(iterator first, iterator last, const
basic_string& s)

I am going to replace the substring specified by first and last and
replace it with s, where s may longer or short than the substring being
replaced. If the replace function suitable for my case ? Anyway, I use
the function in my program,

std::string MyString, ReplaceStr;
...
// get the const_iterator of the substring
// const_iterator1 denotes begin, const_iterator2 denotes end
MyString.replace( const_iterator1, const_iterator2, ReplaceStr );
...

but I got the following error, any idea?


error C2664: "std::basic_string<_Elem,_Traits,_Ax>::_Myt
&std::basic_string<_Elem,_Traits,_Ax>::replace(std::basic_string<_Elem,_Traits,_Ax>::size_type,std::basic_string<_Elem,_Traits,_Ax>::size_type,const
std::basic_string<_Elem,_Traits,_Ax>::_Myt &)" : Cannot convert
"const std::basic_string<_Elem,_Traits,_Ax>::const_iterator" to
"std::basic_string<_Elem,_Traits,_Ax>::size_type"
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
and
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
and
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top