Advertisement
Chieffo

zapis danych do pliku tekstowego

Nov 26th, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream.h>
  3. #include <string.h>
  4. using namespace std;
  5.  
  6. struct osoby{
  7. string nazwisko;
  8. string imie;
  9. int wiek;
  10. };
  11.  
  12.  
  13. int main()
  14. {
  15. int jakasliczbaliczb=3;
  16. osoby t[jakasliczbaliczb];
  17. fstream plik;
  18. plik.open("C:/Users/2b9.SBSMEN.001/Desktop/tekst.txt" , ios::out);
  19.  
  20. if(!plik)
  21. {
  22. cout<<"pliku nie otwarto";
  23. }
  24.  
  25. for(int i=0;i<jakasliczbaliczb;i++)
  26. {
  27. cout<<i+1<<" osoba"<<endl;
  28. cin>>t[i].nazwisko;
  29. cin>>t[i].imie;
  30. cin>>t[i].wiek;
  31. plik<<t[i].nazwisko<<" ";
  32. plik<<t[i].imie<<" "<<t[i].wiek<<endl;
  33.  
  34. }
  35.  
  36.  
  37.  
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement