我试图在数组中存储一个指针。多维数组(C++)
我的指针的指针是类对象是:
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.
我想我的问题是:
- 我是否为文件中的每个单词分配了空间?
- 我将如何将指针存储在我的while/for循环中的ClassObject数组中?
你需要阅读http://stackoverflow.com/editing-help并重新格式化你的问题更具有可读性。 – lothar 2009-04-12 02:33:32