如何继续该计划?

时间:2013-02-04 17:58:32

标签: c++ crash continue

我需要一些文件解析到程序中。但是当我尝试这样做时,我的程序崩溃了。第一个问题是在第一个文件结束时继续执行程序。如何为这部分代码创建一个条件(如果有一个空行继续该程序)?

void ParseNodes(char * file, Field * field){
    char * str =  new char [125];
    fstream nodes;
    nodes.open(file);
    for (int i = 0; i<4; i++){
        nodes.getline(str,125);
    }
    nodes.getline(str, 125);

    { string *s = new string(str);
    int pos = s->find_first_of("1234567890");
    s->erase(0,pos-1);
    field->SetBlocksCount(atoi(s->c_str()));
    delete s;

    nodes.getline(str, 125);
    s = new string(str);
    pos = s->find_first_of("1234567890");
    s->erase(0,pos-1);
    field->SetTerminalCount(atoi(s->c_str()));
    delete s;
    nodes.getline(str,125);

    while ( nodes.good()){
        nodes.getline(str, 125);
        cout<<str<<endl;
        if(strlen(
        s= new string(str);
        if (s->find("terminal")==string::npos){
        pos = s->find_first_not_of("a1234567890");
        field->blocks.push_back(Rect());
        field->blocks.back().name = s->substr(0,pos);
        s->erase(0,pos);
        string*sk= new string(*s);
        *sk=sk->substr(2,40);
        *sk=sk->substr(sk->find_first_not_of("a1234567890"),5);
        //cin.get();
        //cout<<s->c_str()<<'/'<<sk->c_str()<<'|'<<atof(sk->c_str())<<endl;
        field->blocks.back().SetWidth(atof(sk->c_str()));
        pos = s->find_last_not_of("1234567890.");

        s->erase(0,pos);

        field->blocks.back().SetHeight(atof(s->c_str()));
        }

        delete s;
    } }


    delete[] str;
    nodes.close();
}

0 个答案:

没有答案