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>
]
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>
]