问题遇到的现象和发生背景
引发了异常: 写入访问权限冲突。
store 是 0x1920111。
问题相关代码,请勿粘贴截图
void HuffmanTree::docode(huffcode& code, int n)
{
code = new char* [n + 1];
char* store = new char[n];
//零时存放编码
store[n - 1] = '\0';
int start, c, i, f;
for (i = 1; i <= n; i++)
{
start = n - 1;
c = i;
f = huffTree[i].parent;
while (f != 0)
{
--start;
if (huffTree[f].lchild == c)
store[start] = '0';
else
store[start] = '1';
c = f; f = huffTree[f].parent;
}
code[i] = new char[n - start];
code[i] = &store[start];
}
delete store;
fstream outFile("编码.txt", ios::out);
for (int i = 1; i <= n; i++)
{
outFile << huffTree[i].ascii << " " << huffTree[i].weight << " ";//写入字符,权值
while (!code[i])
{
outFile << code[i];//写入编码
}outFile << endl;
}
outFile.close();
}