No one has voted on any posts yet. Votes from other community members are used to determine a member's reputation amongst their peers.
5 Posted Topics
Dreading memory leaks, I would like to make sure I have an understanding of the following code: [code=CPP] //vector initialized to allocate 10 string objects vector<string> *pvec1 = new vector<string>(10); delete pvec1; //10 vector<string> objects vector<string> *pvec2 = new vector<string>[10]; pvec2[0].push_back("test1"); delete [] pvec2; [/code] 1> Would executing the preceding … | |
Re: Looking at your code, it looks like your intention is to simultaneously return a pointer to the "copied" array [B]and[/B] clean up the memory allocated by the old array. Having a function perform that task for you can be troublesome because your code doesn't know whether the old array is … | |
Re: Well, for simplicity, we could repeatedly "trim" the string based on its delimiter. [code=CPP] string rTrimString(string thisString, int occurrence, string delimiter) { for(int i = occurrence - 1; i >= 0; --i) thisString = thisString.substr(0, thisString.rfind(delimiter)); return thisString; } [/code] so, for example, [code] string test = "1,2,3,4,5,6,7,8,9"; cout << … | |
The following code works fine with "Release" config, but gets this odd "HEAP_CORRUPTION_DETECTED" error when I try to execute in the "Debug" config. I am using visual studio 2005, default settings. Also, I looked into deleting multi-dimensional objects, and it appears I am doing it correctly here ([url]http://www.daniweb.com/forums/thread6511.html)[/url]. Pretty simple … |
The End.