Ok, that's the problem. Now try to come to an algorithmic solution.
That doesn't need to be C or C++, just pseudocode.
Only when you find your algorithm looks meaningful, try to code it!
Than: the problem is not well formed. Do you want only two char-s combination? Does the input string needs to be 3 char-s wide or can it be whatever?
Be sure about that: you risk to produce a code that works on a very specific case, while looking for something more generic.
I am try to make number of possible key combination.I use google then i found number of example permutation and combination.There is common result in permutation and combination ignore repeated
Can any any help to permutation and combination ignore allowed?
What will happen to the memory allocated for "hello"? Will it be released at assignment of "world"?
Yes. The current content of a CString variable will be automatically released when the variable goes out of scope, as well.
Would someone like to explain why this has been 1-voted? The answer is correct. There may be some hedging involved as to whether new memory is actually allocated depending on the length of the two strings, as Joe pointed out, but the point is the reassignment of the variable will not result in a leak.
THAT was the question.
I assume the individual who voted it a 1 will now present some proof indicating that a leak WILL occur, justifying the 1?
CString is MFC class.
And the buffer it uses inside this class is handled by CString, it has nothing to do with user unless you are creating a pointer of the CString( Which is not at a good practice.)
Inside this CString class, destructor is having the code to delete the memory allocated for its internal buffer. So dont worrry, CString will delete that memory for you when it goes out of scope
It will release the memory of previously allocated pointer on the = operator of CString.
See the code of CString.
The specified function is called inside the = operator.
void CString::AllocBeforeWrite(int nLen)
if (GetData()->nRefs > 1 || nLen > GetData()->nAllocLength)
// This release will release all the memory allocated previously, so you wont face any memory leak.
ASSERT(GetData()->nRefs <= 1);
Since "world" is the same length as "hello", no reallocation will be done; "world" will just overwrite "hello".
If you set a string "hello world", the internal buffer would be reallocated in a safe manner, resulting in no leak. (For optimization reasons, CString sometimes allocates a larger buffer than requested, so even setting a larger string won't result in a reallocation.)