Jump to content
  • Advertisement
Sign in to follow this  
utilae

Problems with string.append()

This topic is 4891 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to append some characters to the end of a string, but I get an error. I am using c++. string sName="John"; sName.append(1,"_Smith"); There error I get is: "error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::_Myt &std::basic_string<_Elem,_Traits,_Ax>::append(const _Elem *,std::basic_string<_Elem,_Traits,_Ax>::size_type)' : cannot convert parameter 2 from 'char *' to 'const char *' with [ _Elem=char, _Traits=std::char_traits<char>, _Ax=std::allocator<char> ] Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast" Anyone able to help?

Share this post


Link to post
Share on other sites
Advertisement
I think what you're trying to do is:

string sName = "John";
sName += "_Smith";

There is a function called append in std::string that takes those parameters, but you've got them backwards.

Share this post


Link to post
Share on other sites
If you are curious why the original function call didn't work, the form of string::append() that takes an integer as the first argument asks for a single char as the second argument, not a whole string. You probably wanted to do sName.append("_Smith");

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!