2

I'm trying to write a program that gets a sequence of words, put them into a vector and then does things with them. I've found one way that works, which is:

{
    vector<string> inputs;
    string Input;
    cin >> Input;
    while (Input != "Quit") 
    {
        inputs.push_back(Input);
        cin >> Input;
    }
}

However I'm trying to use another method to do it, which is:

{
    istream_iterator<string> ii(cin);
    istream_iterator<string> eos;
    vector<string> inputs(ii, eos);
}

But I have no idea how to make Quit mean EOF, which would end the input stream and put the words into the vector. How do I make the string "Quit" act as a stream terminator?

1 Answers1

1

EOF is defined as -1 in cstdio. You could try #undef EOF and #define EOF "Quit", but this will probably break implementations that rely on EOF being a signed integer and/or -1. So basically, leave it alone.