Link to home
Start Free TrialLog in
Avatar of lapucca
lapucca

asked on

Do I need to resize wstring if it already has a string but I'm assigning a new string with different size?

The following variables are all wstring.  However, those in userDataIter(vector Iterator) points to already has a string them.  Would the code below be correct as far as the memory goes for wstring?  Thank you.

            if(!(userData->LoginName.empty())&& (LoginNameChanged))      
            {
                  userDataIter->LoginName.clear();
                  userDataIter->LoginName = userData->LoginName;
            }

            if(!(userData->shell.empty())&& (shellChanged))
            {
                  userDataIter->shell.clear();
                  userDataIter->shell = userData->shell;
Avatar of jkr
jkr
Flag of Germany image

If you're talking about a 'std::wstring' - no, not at all. The string object itself will take care about that.
ASKER CERTIFIED SOLUTION
Avatar of rajeev_devin
rajeev_devin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
???

You asked whether you need to resiue a string - I answered 'No'. Is that incoorect? No, it isn't... So I cannot quite understand on which basis you are picking your answers.
Avatar of lapucca
lapucca

ASKER

Hi jkr,

Your answer is correct and was posted an hour earlier.  I should have accept your answer instead.  I picked rajeev's answer becuase he also point out the other question I meant to ask, do I need to clear the string firs (_bstr_t requires detach first).  

Anyway, you're still correct.  I'll pick my answer more carefully next time based on my question.  Thank you.