Я пытаюсь сохранить указатель в массиве.
Мой указатель на указатель - это объект класса:
classType **ClassObject;
Итак, я знаю, что могу выделить его с помощью нового оператора следующим образом:
ClassObject = new *classType[ 100 ] = {};
Я читаю текстовый файл с пунктуацией, и вот что у меня есть:
// included libraries
// main function
// defined varaibles
classType **ClassObject; // global object
const int NELEMENTS = 100; // global index
wrdCount = 1; // start this at 1 for the 1st word
while ( !inFile.eof() )
{
getline( inFile, str, '\n' ); // read all data into a string varaible
str = removePunct(str); // User Defined Function to remove all punctuation.
for ( unsigned x = 0; x < str.length(); x++ )
{
if ( str[x] == ' ' )
{
wrdCount++; // Incrementing at each space
ClassObject[x] = new *classType[x];
// What i want to do here is allocate space for each word read from the file.
}
}
}
// this function just replaces all punctionation with a space
string removePunct(string &str)
{
for ( unsigned x = 0; x < str.length(); x++ )
if ( ispunct( str[x] ) )
str[x] = ' ';
return str;
}
// Thats about it.
Я думаю, что мои вопросы:
- Выделил ли я место для каждого слова в файле?
- Как мне сохранить указатель в массиве ClassObject в цикле while/for?