Why doesn't this for-loop execute?

Posted by Maulrus on Stack Overflow See other posts from Stack Overflow or by Maulrus
Published on 2010-05-02T01:18:18Z Indexed on 2010/05/02 1:27 UTC
Read the original article Hit count: 260

Filed under:
|
|

I'm writing a program for an exercise that will read data from a file and format it to be readable. So far, I have a bit of code that will separate a header from the data that goes under it. Here it is:

int main() {
    ifstream in("records.txt");
    ofstream out("formatted_records.txt");
    vector<string> temp;
    vector<string> headers;
    for (int i = 0; getline(in,temp[i]); ++i) {
        static int k = -1;
        if (str_isalpha(temp[i])) {
            headers[++k] = temp[i];
            temp.erase(temp.begin() + i);
        }
        else {
            temp[i] += "," + headers[k];
        }
    }
}

(str_isalpha() is just a function that applies isalpha() to every character in a string.) Now, the for-loop in this program doesn't execute, and I can't figure out why. Does anybody know?

© Stack Overflow or respective owner

Related posts about c++

Related posts about for-loop