运行以下代码时出现的错误是“Debug Assertation Failed... Expression _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)”。
我的 readTXT 方法需要传递一个 char* 对象,但我想允许用户选择为自己输入值。
char * mapName;
int main()
{
//load map
int mapSelection;
cout << "select a map";
cin >> mapSelection;
switch (mapSelection)
{
case 1:
mapName = "walls1.txt";
break;
case 2:
mapName = "walls2.txt";
break;
case 3:
mapName = "maze1.txt";
break;
case 4:
mapName = "maze2.txt";
break;
}
map = readTXT(mapName, 8, 11);
delete mapName;
...
这是 readTXT 方法的代码
double* readTXT(char *fileName, int sizeR, int sizeC)
{
double* data = new double[sizeR*sizeC];
int i=0;
ifstream myfile (fileName);
if (myfile.is_open())
{
while ( myfile.good())
{
if (i>sizeR*sizeC-1) break;
myfile >> *(data+i);
cout << *(data+i) << ' '; // This line display the converted data on the screen, you may comment it out.
if (i == 10 || i == 21 || i == 32 || i == 43 || i == 54 || i == 65 || i == 76)
{
cout << "\n";
}
i++;
}
myfile.close();
}
else cout << "Unable to open file";
//cout << i;
return data;
}