我有如下功能
int* readFile(string InputPath)
{
int *myvar = new int[10]; //The file has 10 lines (Using heap)
ifstream inFile;
inFile.open(InputPath.c_str(), ios::in);
if (inFile.fail())
{
cout << "Error reading the input file ";
cout << InputPath << ".";
exit(0);
}
string fileLine;
while (getline(inFile, fileLine))
{
myvar[i]=toint(fileLine); //will be converted to int!
}
;
inFile.close();
return myvar;
}:
如何释放堆(myvar)?一般来说,返回此类数组的最佳方法是什么?