我在运行此代码时遇到错误。执行时会发出错误,如 -
在抛出'std :: out_of_range'的实例后终止调用 what():basic_string :: substr
关于我在这里做错了什么想法?
#include <string.h>
#include <cstring>
#include <string>
#include <iostream>
#include <fstream>
#include "fix_nvt.h"
#include "group.h"
#include "modify.h"
#include "error.h"
using namespace LAMMPS_NS;
using namespace FixConst;
using namespace std;
std::ifstream inFile;
double x,y,z;
string str_val;
/* ---------------------------------------------------------------------- */
FixNVT::FixNVT(LAMMPS *lmp, int narg, char **arg) :
FixNH(lmp, narg, arg)
{
if (!tstat_flag)
error->all(FLERR,"Temperature control must be used with fix nvt");
if (pstat_flag)
error->all(FLERR,"Pressure control can not be used with fix nvt");
// create a new compute temp style
// id = fix-ID + temp
int n = strlen(id) + 6;
id_temp = new char[n];
strcpy(id_temp,id);
strcat(id_temp,"_temp");
char **newarg = new char*[3];
newarg[0] = id_temp;
newarg[1] = group->names[igroup];
newarg[2] = (char *) "temp";
modify->add_compute(3,newarg);
delete [] newarg;
tflag = 1;
printf("syracuse rocks\n\n\n");
inFile.open("matrix.txt", ios::in);
while(getline(inFile,str_val));
{
x = atof(str_val.substr(1,4).c_str());
y = atof(str_val.substr(17,4).c_str());
z = atof(str_val.substr(33,4).c_str());
printf ("x = %f, y =%f, z=%f\n",x,y,z);
}
inFile.close();
}