Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

basic_string::insert problem - urgent ...

Status
Not open for further replies.

SteveBrett

Programmer
Apr 24, 2000
107
0
0
MT
hello all,

this is driving me crazy !!!

i need to replace all the occurences on '&' with '&' in a string of xml but can't seem to get the paramters of the insert function correct.

the string is defined as:

std::wstring m_objStrReturnXml;

this is the code i have as present:

const char *escamp = "amp;";

for(int x=0; x < m_objStrReturnXml.length(); x++)
{
if (m_objStrReturnXml[x] == '&')
{
m_objStrReturnXml.insert(x+1, escamp);
}
}

when i try to build it i get:

error C2664: 'class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > &__thisca
ll std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> >::insert(unsigned int,const class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigne
d short> > &)' : cannot convert parameter 2 from 'const char *' to 'const class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > &'
Reason: cannot convert from 'const char *' to 'const class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> >'
No constructor could take the source type, or constructor overload resolution was ambiguous
 
fixed it. the problem was the char* should have been wchar_t* (as pointed out by a colleague in another department)

the working code is:

const wchar_t *escamp = L"amp;";

for(int x=0; x < m_objStrReturnXml.length(); x++)
{
if (m_objStrReturnXml[x] == '&')
{
m_objStrReturnXml.insert(x+1, escamp);
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top