I'm reading in a file, line by line. Each line contains values delimited by a colon. I won't know how many lines are going to be in the file, but I DO know how many values are going to be delimited for each line. After tokenizing each line, I'm trying to store the values in a two-dimensional array using STL's <vector>. Each entry in the array contains another vector array of wide char pointers that will each point to a newly allocated wide char string. I'm having trouble deallocating the vector. Currently, I have something like the following.
// Channels is defined like this...
vector< vector<wchar_t*> > Channels;
// Reading in the data goes something like this...
// Read data in, line by line.
while ( ReadLine(hFile, szwLine) > 0 ) {
if ( wcsstr(szwLine, L"CHANNEL=") != NULL ) {
// Create a new index for Channel array.
g_stAI.Channels.push_back(
vector<wchar_t*>() );
// Determine if line read in is a channel place holder.
if ( wcsstr(szwLine, L"PLACEHOLDER") != NULL ) {
pTemp = new wchar_t[wcslen(L"PLACEHOLD
ER")*sizeo
f(wchar_t)
+1];
wcscpy( pTemp, L"PLACEHOLDER" );
g_stAI.Channels[iCount].pu
sh_back( pTemp );
} else {
// Parse data
pDummy = wcstok( szwLine, L"=" );
pChanName = wcstok( NULL, L":" );
pChanID = wcstok( NULL, L":" );
pChanUseHigh = wcstok( NULL, L":" );
pChanHighVal = wcstok( NULL, L":" );
pChanUseLow = wcstok( NULL, L":" );
pChanLowVal = wcstok( NULL, L":" );
pTemp = new wchar_t[wcslen(pChanName)*
sizeof(wch
ar_t)+1];
wcscpy( pTemp, pChanName );
g_stAI.Channels[iCount].pu
sh_back( pTemp );
pTemp = new wchar_t[wcslen(pChanID)*si
zeof(wchar
_t)+1];
wcscpy( pTemp, pChanID );
g_stAI.Channels[iCount].pu
sh_back( pTemp );
pTemp = new wchar_t[wcslen(pChanUseHig
h)*sizeof(
wchar_t)+1
];
wcscpy( pTemp, pChanUseHigh );
g_stAI.Channels[iCount].pu
sh_back( pTemp );
pTemp = new wchar_t[wcslen(pChanHighVa
l)*sizeof(
wchar_t)+1
];
wcscpy( pTemp, pChanHighVal );
g_stAI.Channels[iCount].pu
sh_back( pTemp );
pTemp = new wchar_t[wcslen(pChanUseLow
)*sizeof(w
char_t)+1]
;
wcscpy( pTemp, pChanUseLow );
g_stAI.Channels[iCount].pu
sh_back( pTemp );
pTemp = new wchar_t[wcslen(pChanLowVal
)*sizeof(w
char_t)+1]
;
wcscpy( pTemp, pChanLowVal );
g_stAI.Channels[iCount].pu
sh_back( pTemp );
}
iCount++;
}
}
When I'm ready to deallocate all values in the vector, how would I go about it? If someone could help me out, I would surely appreciate it. If possible, please post code for the deallocation. Or if anyone knows of a simpler way to do this, please let me know.
Any help would be much appreciated.
Thanks