Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. // Kolokwium.cpp : Ten plik zawiera funkcję „main”. W nim rozpoczyna się i kończy wykonywanie programu.
  2. //
  3.  
  4. #include <iostream>
  5. #include <fstream>
  6. #include <vector>
  7. #include <string>
  8. using namespace std;
  9.  
  10. struct para {
  11. double x, y;
  12. para(double _x, double _y);
  13. };
  14. para::para(double _x, double _y) {
  15. x = _x;
  16. y = _y;
  17. };
  18.  
  19. para createPara();
  20. void saveToFile(vector<para> vector, int size);
  21. void readFromFile();
  22.  
  23. int main()
  24. {
  25. setlocale(LC_ALL, "pl_PL");
  26. vector<para> w;
  27. for (int i = 0; i < 3; i++) {
  28. w.push_back( createPara() );
  29. }
  30. saveToFile(w, 3);
  31. readFromFile();
  32.  
  33. system("PAUSE");
  34. return 0;
  35. }
  36.  
  37. para createPara() {
  38. double a, b;
  39. cout << "Wprowadz parę liczb\n";
  40. cin >> a >> b;
  41. para p(a, b);
  42. return p;
  43. }
  44.  
  45. void saveToFile(vector<para> vector, int size) {
  46. ofstream file("text.txt", ios::out);
  47. for (int i = 0; i < size; i++) {
  48. file << vector[i].x << " " << vector[i].y << " ";
  49. }
  50. file.close();
  51. }
  52.  
  53. void readFromFile() {
  54. string buffer;
  55. ifstream file("text.txt");
  56. if (!file.good()) cout << "Nie udało się otworzyć pliku!\n";
  57. else while (!file.eof()) {
  58. getline(file, buffer);
  59. cout << buffer << " ";
  60. }
  61. file.close();
  62. cout << endl;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement