read file in C++

Posted by Amm Sokun on Stack Overflow See other posts from Stack Overflow or by Amm Sokun
Published on 2011-06-28T05:24:43Z Indexed on 2011/06/28 8:22 UTC
Read the original article Hit count: 356

Filed under:
|
|

I am trying to read a list of words from a file in C++. However, the last word is read twice. I cannot understand why it is so. Can someone help me out?

int main () {

ifstream fin, finn;
vector<string> vin;
vector<string> typo;
string word;
fin.open("F:\\coursework\\pz\\gattaca\\breathanalyzer\\file.in");
if (!fin.is_open())
    cout<<"Not open\n";
while (fin) {
    fin >> word;
    cout<<word<<endl;
    vin.push_back(word);
}
fin.close();
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about homework