468,469 Members | 2,078 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,469 developers. It's quick & easy.

string.replace help

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_iterat or" to
"std::basic_string<_Elem,_Traits,_Ax>::size_ty pe"
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>
]

Jul 27 '06 #1
1 6445
MCH wrote:
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)
Get better documentation or see your C++ reference text of choice. Try
this: http://www.cppreference.com/cppstring/replace.html

Cheers! --M

Jul 27 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by FrzzMan | last post: by
32 posts views Thread by tshad | last post: by
4 posts views Thread by Derek Martin | last post: by
16 posts views Thread by BBM | last post: by
16 posts views Thread by ^MisterJingo^ | last post: by
5 posts views Thread by int main(void) | last post: by
1 post views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.