Jump to content
  • Advertisement
Sign in to follow this  
SIAS87

appending to LPCWSTR

This topic is 3640 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

hi prob a very simple answer but i cant find it anywhere. i am trying to add extra characters to a LPCWSTR. currently: //modelloc is obtained from function LPCWSTR modelloc = L"MP_Urban"; //need to append this after obtaining from function modelloc += L".X"; any help would be great Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
You can't and shouldn't like that.

Firstly, LPCWSTR stands for "Long Pointer to Constant Wide String". Key word here is constant. Which means you can't modify it.

Secondly, it points to a string literal, which might be placed in read-only memory. Writing to that to append characters (e.g. using wcscat) could result in your program crashing.

Instead, use std::wstring:

std::wstring modelloc(L"MP_Urban");
modelloc += L".X";



Works exactly like you want.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!