Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- using namespace std;
- string imie,nazwisko;
- int tel;
- int main()
- {
- fstream plik;
- plik.open("wizytowka.txt",ios::in);
- if (plik.good()==false) { cout<<"Plik nie istnieje...";
- exit(0);
- }
- string linia_tekstu;
- int nr_linii=1;
- while (getline(plik, linia_tekstu)) {
- switch(nr_linii){
- case 1: imie = linia_tekstu;
- break;
- case 2: nazwisko = linia_tekstu;
- break;
- case 3: tel = atoi(linia_tekstu.c_str());
- break;
- }
- nr_linii++;
- }
- cout<<"Imie: "<<imie<<endl<<"Nazwisko: "<<nazwisko<<endl<<"Nr telefonu: "<<tel<<endl;
- plik.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement