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 (

Pretty simple code, imho:

void readStrVec() {
	vector<string> strVec;
	string thisString = "";

	while(cin >> 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?


*smacks forehead*

Thanks so much. Migrating from C (char *) to C++ strings had me carelessly forgetting about those pesky null characters, and the debug error didn't help much :P

This question has already been answered. Start a new discussion instead.