Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5. using namespace std;
  6.  
  7. //By Aves
  8.  
  9. struct date {
  10. int day;
  11. string month;
  12. };
  13.  
  14. struct S : date {
  15. float value;
  16.  
  17. S(int dayNumber, string monthString, float value) {
  18. this->day = dayNumber;
  19. this->month = monthString;
  20. this->value = value;
  21. }
  22. };
  23.  
  24. S* createStruct() {
  25. int day; string month; float value;
  26. cin >> day >> month >> value;
  27. S* structS = new S(day, month, value);
  28. return structS;
  29. }
  30.  
  31. void writeToFile() {
  32. S* struct1 = createStruct();
  33. S* struct2 = createStruct();
  34. ofstream writeFile;
  35. writeFile.open("file.txt", ios::app);
  36. writeFile << struct1->day << " " << struct1->month << " " << struct1->value << endl;
  37. writeFile << struct2->day << " " << struct2->month << " " << struct2->value << endl;
  38. writeFile.close();
  39. }
  40.  
  41. /*
  42. vector <string> fileInput() {
  43. vector <string> fileInput;
  44. string buffer;
  45. ifstream readFile;
  46. readFile.open("file.txt");
  47. while (readFile >> buffer) {
  48. fileInput.push_back(buffer);
  49. }
  50. readFile.close();
  51. return fileInput;
  52. }
  53.  
  54. void printFile(vector <string> fileInput) {
  55. for (auto& value : fileInput) {
  56. cout << value << " ";
  57. }
  58. }
  59. */
  60.  
  61. string* fileInput(int x) {
  62. string* fileInput = new string[x];
  63. string buffer;
  64. ifstream readFile;
  65. readFile.open("file.txt");
  66. int i = 0;
  67. while (readFile >> buffer) {
  68. fileInput[i] = buffer;
  69. i++;
  70. }
  71. readFile.close();
  72. return fileInput;
  73. }
  74.  
  75. void printFile(string* fileInput,int x) {
  76. for (int i = 0; i < x; i++) {
  77. cout << fileInput[i] << " ";
  78. }
  79. }
  80.  
  81. int main() {
  82. cout << "LiczbaElementow";
  83. int x; cin >> x;
  84. writeToFile();
  85. printFile(fileInput(x),x);
  86. return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement