By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,124 Members | 1,528 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,124 IT Pros & Developers. It's quick & easy.

string.replace help

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.