Sign in to follow this  

appending to LPCWSTR

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this