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 (http://www.daniweb.com/forums/thread6511.html).
Pretty simple code, imho:
void readStrVec() {
vector<string> strVec;
string thisString = "";
while(cin >> thisString) {
strVec.push_back(thisString);
}
char **newCStrArray = new char*[strVec.size()];
for(size_t i = 0; i < strVec.size(); i++) {
newCStrArray[i] = new char[strVec[i].size()];
strcpy(newCStrArray[i], strVec[i].c_str());
//Alternatively: (same problem)
//char *cstr = new char[strVec[i].size()];
//strcpy(cstr, strVec[i].c_str());
//newCStrArray[i] = cstr;
cout << newCStrArray[i] << endl;
}
for(size_t i = 0; i < strVec.size(); i++) {
delete [] newCStrArray[i];
}
delete [] newCStrArray;
}
Any ideas?
Thanks.