int main() {
string xs;
string* atom=new string[60000];
string* aa=new string[60000];
string* pos=new string[60000];
string* aaid=new string[60000];
string* chain=new string[60000];
string* X=new string[60000];
string* Y=new string[60000];
string* Z=new string[60000];
string* occupancy=new string[60000];
string* bfactor=new string[60000];
ifstream inFile;
inFile.open ("1ASO.pdb"); //similar to 1ASO.txt
//middle codes
delete [] atom;
delete [] aa;
delete [] pos;
delete [] aaid;
delete [] chain;
delete [] X;
delete [] Y;
delete [] Z;
delete [] occupancy;
delete [] bfactor;
inFile.close();
}
这段代码工作得很好,但是当我将其更改为通过命令提示符输入文件时(如下所示),对于特定文件(如1ASO.pdb),它会崩溃。我在命令提示符中使用以下命令运行所有pdb文件的程序。
For %f in (*.pdb)执行程序"%f"
我的猜测是我正在做动态内存分配错误,但不确定如何修复它。
int main(int argc, char* argv[]) {
string xs;
string* atom=new string[60000];
string* aa=new string[60000];
string* pos=new string[60000];
string* aaid=new string[60000];
string* chain=new string[60000];
string* X=new string[60000];
string* Y=new string[60000];
string* Z=new string[60000];
string* occupancy=new string[60000];
string* bfactor=new string[60000];
ifstream inFile;
inFile.open (argv[1]); //similar to 1ASO.txt
//middle codes
delete [] atom;
delete [] aa;
delete [] pos;
delete [] aaid;
delete [] chain;
delete [] X;
delete [] Y;
delete [] Z;
delete [] occupancy;
delete [] bfactor;
inFile.close();
}
你分配这些字符串有什么特殊的原因吗?为什么不直接将它们声明为局部变量呢?
你看过argv[1]是什么吗?您确定这是您想要的文件名吗?