stringstream problem - vector iterator not dereferencable

Posted by andreas on Stack Overflow See other posts from Stack Overflow or by andreas
Published on 2010-04-19T13:16:12Z Indexed on 2010/04/19 13:23 UTC
Read the original article Hit count: 365

Filed under:
|
|

Hello

I've got a problem with the following code snippet.

It is related to the stringstream "stringstream css(cv.back())" bit. If it is commented out the program will run ok.

It is really weird, as I keep getting it in some of my programs, but if I just create a console project the code will run fine. In some of my Win32 programs it will and in some it won't (then it will return "vector iterator not dereferencable" but it will compile just fine).

Any ideas at all would be really appreciated. Thanks!

vector<double> cRes(2);
vector<double> pRes(2);

int readTimeVects2(vector<double> &cRes, vector<double> &pRes){
    string segments;
    vector<string> cv, pv, chv, phv;
    ifstream cin("cm.txt");
    ifstream pin("pw.txt");
    ifstream chin("hm.txt");
    ifstream phin("hw.txt");

    while (getline(cin,segments,'\t')) {
        cv.push_back(segments);
    }

    while (getline(pin,segments,'\t')) {
        pv.push_back(segments);
    }

    while (getline(chin,segments,'\t')) {
        chv.push_back(segments);
    }

    while (getline(phin,segments,'\t')) {
        phv.push_back(segments);
    }

    cin.close();  
    pin.close();  
    chin.close();   
    phin.close();

    stringstream phss(phv.front());
    phss >> pRes[0];
    phss.clear();
    stringstream chss(chv.front());
    chss >> cRes[0];
    chss.clear();

    stringstream pss(pv.back());
    pss >> pRes[1];
    pss.clear();
    stringstream css(cv.back());
    css >> cRes[1];
    css.clear();

    return 0;
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about stl