Why appear the string yeahh twice?

Hi, why appear the string "yeahh" twice in the code:

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
fstream sexo("cuzin.txt");
ifstream sexo2("cuzin.txt");
string aux;

sexo << "cu " << "putaria" << " yeahh" << endl;

while(!sexo2.eof()){
sexo2 >> aux;
cout << aux << " ";
}
sexo2.close();
return 0;
}

Becaue you are looping on eof which is incorrect. You should loop on input operations:
1
2
3
while (sexo2 >> aux) {
    cout << aux << " ";
}
Topic archived. No new replies allowed.