Program szukający w pliku adresów e mail, i zapisujący je do pliku

0

Oto mój kod, kompiluje się i działa jeśli po mailu nic nie ma, pomógłby ktoś naprawić bo nie mogę znaleźć błędu
dana z pliku powinny wyglądać np tak: Jan Kowalski [email protected] 75755780 Warszawa Adam Nowak [email protected] 67778
i program powinien wypisywać maile

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

void fun1(ifstream& is, ofstream& plik)

{
    string napis;
    is >> napis;
    string str = "";
    size_t poz1 = 0, poz2 = 0;
    do {
        is >> napis;
        poz1 = napis.find(' ', poz2);
        str = napis.substr(poz2, poz1 - poz2);
        poz2 = poz1 + 1;
        if (napis.find('@') != string::npos)
            plik << str << ", ";
    } while (poz1 != string::npos);
    cout << endl;
}

int main()
{

    ifstream cin;
    cin.open("cin.txt");

    ofstream plik("out.txt");
    fun1(cin, plik);

    plik.close();
    cin.close();
    return 0;
}
2

Zły warunek wyjściowy z pętli :)


#include <iostream>
#include <fstream>
#include <string>

using namespace std;

void fun1(ifstream& is, ofstream& plik)

{
    string napis;
    is >> napis;
    string str = "";
    size_t poz1 = 0, poz2 = 0;
    do {
        cout<<napis<<endl;
        poz1 = napis.find(' ', poz2);
        str = napis.substr(poz2, poz1 - poz2);
        poz2 = poz1 + 1;
        if (napis.find('@') != string::npos)
            plik << str << ", ";
    } while (is >> napis);
    cout << endl;
}

int main()
{

    ifstream we;
    we.open("cin.txt");

    ofstream plik("out.txt");
    fun1(we, plik);

    plik.close();
    we.close();
    return 0;
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1