Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2006-04-27
4
Medium Priority
?
269 Views
Last Modified: 2012-06-21
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;
0
Comment
Question by:lapucca
  • 2
4 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 16558930
If you're talking about a 'std::wstring' - no, not at all. The string object itself will take care about that.
0
 
LVL 12

Accepted Solution

by:
rajeev_devin earned 1000 total points
ID: 16559158
>>               userDataIter->LoginName.clear();
>>               userDataIter->LoginName = userData->LoginName;
I find the first statement useless. Since you are assigning in the next line.
You can remove that statement.
0
 
LVL 86

Expert Comment

by:jkr
ID: 16563685
???

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

Author Comment

by:lapucca
ID: 16574140
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.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question