String 调试断言失败:字符串下标超出范围

String 调试断言失败:字符串下标超出范围,string,if-statement,vector,visual-studio-debugging,outofrangeexception,String,If Statement,Vector,Visual Studio Debugging,Outofrangeexception,我得到一个下标超出范围的错误。 这是它发生的函数: //Load Object Function int loadObejct(const char *fileName) { cout<<"soos"; vector<string*> coord; vector<coordinate*> vertex; vector<face*> faces; vector<coordinate*> normals; ifstream in(fileN

我得到一个下标超出范围的错误。 这是它发生的函数:

//Load Object Function
int loadObejct(const char *fileName)
{
cout<<"soos";
vector<string*> coord;
vector<coordinate*> vertex;
vector<face*> faces;
vector<coordinate*> normals;
ifstream in(fileName);

if(!in.is_open())
{
    cout<<"no file";
    return 5;
}

char buf[400];

while(!in.eof())
{
    in.getline(buf, 400);
    coord.push_back(new string(buf));
    cout<<"loading";
}
////////////////////////////////////////////where error starts
for(int i = 0; i<coord.size(); i++)
{
    if((*coord[i])[0] =='#' || (*coord[i])[0] == 'g')
    {
        continue;
    }
    else if((*coord[i])[0]=='v' && (*coord[i])[1]==' ' )
    {
        float tmpx, tmpy, tmpz;
        sscanf(coord[i]->c_str(), "v  %f %f %f", &tmpx, &tmpy, &tmpz);
        vertex.push_back(new coordinate(tmpx, tmpy, tmpz));
    }else if((*coord[i])[0]=='v' && (*coord[i])[1]=='n' )
    {
        float tmpx, tmpy, tmpz;
        sscanf(coord[i]->c_str(), "vn %f %f %f", &tmpx, &tmpy, &tmpz);
        normals.push_back(new coordinate(tmpx, tmpy, tmpz));
    }else if((*coord[i])[0]=='f')
    {
        int a, b, c, d, e;
        if(count(coord[i]->begin(), coord[i]->end(), ' ') == 4)
        {
            sscanf(coord[i]->c_str(), "f %d//%d %d//%d %d//%d %d//%d", &a, &b, &c, &b, &d, &b, &e, &b);
            faces.push_back(new face(b, a, c, d, e));
        }else
        {
            sscanf(coord[i]->c_str(), "f %d//%d %d//%d %d//%d", &a, &b, &c, &b, &d, &b);
            faces.push_back(new face(b, a, c, d));

        }
    }
}///////////////////////////////where error ends
//draw

int num;
num = GL::GenLists(1);
GL::NewList(num, ListMode::Compile);

for(int i = 0; i<faces.size(); i++)
{
    if(faces[i]->four == true)
    {
        GL::Begin(BeginMode::Quads);
        GL::Normal3(normals[faces[i]->faceNum-1]->x, normals[faces[i]->faceNum-1]->y, normals[faces[i]->faceNum-1]->z);
        GL::Vertex3(vertex[faces[i]->faces[0]-1]->x, vertex[faces[i]->faces[0]-1]->y, vertex[faces[i]->faces[0]-1]->z);
        GL::Vertex3(vertex[faces[i]->faces[1]-1]->x, vertex[faces[i]->faces[1]-1]->y, vertex[faces[i]->faces[1]-1]->z);
        GL::Vertex3(vertex[faces[i]->faces[2]-1]->x, vertex[faces[i]->faces[2]-1]->y, vertex[faces[i]->faces[2]-1]->z);
        GL::Vertex3(vertex[faces[i]->faces[3]-1]->x, vertex[faces[i]->faces[3]-1]->y, vertex[faces[i]->faces[3]-1]->z);
        GL::End();
    }else
    {
        GL::Begin(BeginMode::Triangles);
        GL::Normal3(normals[faces[i]->faceNum-1]->x, normals[faces[i]->faceNum-1]->y, normals[faces[i]->faceNum-1]->z);
        GL::Vertex3(vertex[faces[i]->faces[0]-1]->x, vertex[faces[i]->faces[0]-1]->y, vertex[faces[i]->faces[0]-1]->z);
        GL::Vertex3(vertex[faces[i]->faces[1]-1]->x, vertex[faces[i]->faces[1]-1]->y, vertex[faces[i]->faces[1]-1]->z);
        GL::Vertex3(vertex[faces[i]->faces[2]-1]->x, vertex[faces[i]->faces[2]-1]->y, vertex[faces[i]->faces[2]-1]->z);
        GL::End();
    }
}
GL::EndList();

//end draw
for(int i = 0; i<coord.size(); i++)
{
    delete coord[i];
}
for(int i = 0; i<faces.size(); i++)
{
    delete normals[i];
}
for(int i = 0; i<normals.size(); i++)
{
    delete faces[i];
}
for(int i = 0; i<vertex.size(); i++)
{
    delete vertex[i];
}


return 6;
}
//加载对象函数
int loadObejct(常量字符*文件名)
{
coutfaceNum-1]->x,法线[faces[i]->faceNum-1]->y,法线[faces[i]->faceNum-1]->z);
GL::Vertex3(顶点[面[i]->面[0]-1]->x,顶点[面[i]->面[0]-1]->y,顶点[面[i]->面[0]-1]->z);
GL::Vertex3(顶点[faces[i]->faces[1]-1]->x,顶点[faces[i]->faces[1]-1]->y,顶点[faces[i]->faces[1]-1]->z);
GL::Vertex3(顶点[面[i]->面[2]-1]->x,顶点[面[i]->面[2]-1]->y,顶点[面[i]->面[2]-1]->z);
GL::Vertex3(顶点[面[i]->面[3]-1]->x,顶点[面[i]->面[3]-1]->y,顶点[面[i]->面[3]-1]->z);
GL::End();
}否则
{
GL::Begin(BeginMode::三角形);
GL::Normal3(法线[faces[i]->faceNum-1]->x,法线[faces[i]->faceNum-1]->y,法线[faces[i]->faceNum-1]->z);
GL::Vertex3(顶点[面[i]->面[0]-1]->x,顶点[面[i]->面[0]-1]->y,顶点[面[i]->面[0]-1]->z);
GL::Vertex3(顶点[faces[i]->faces[1]-1]->x,顶点[faces[i]->faces[1]-1]->y,顶点[faces[i]->faces[1]-1]->z);
GL::Vertex3(顶点[面[i]->面[2]-1]->x,顶点[面[i]->面[2]-1]->y,顶点[面[i]->面[2]-1]->z);
GL::End();
}
}
GL::EndList();
//末端牵引

for(int i=0;iThat sscanf()的用法是黑板上的指甲。错误的、糟糕的格式说明符会破坏堆栈,很有可能是
i
变量更改并导致错误。停止这样做,你已经可以访问成员了。嗯,你说的有道理……你知道我可以用什么来代替它吗?