Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- using namespace std;
- //By Aves
- struct date {
- int day;
- string month;
- };
- struct S : date {
- float value;
- S(int dayNumber, string monthString, float value) {
- this->day = dayNumber;
- this->month = monthString;
- this->value = value;
- }
- };
- S* createStruct() {
- int day; string month; float value;
- cin >> day >> month >> value;
- S* structS = new S(day, month, value);
- return structS;
- }
- void writeToFile() {
- S* struct1 = createStruct();
- S* struct2 = createStruct();
- ofstream writeFile;
- writeFile.open("file.txt", ios::app);
- writeFile << struct1->day << " " << struct1->month << " " << struct1->value << endl;
- writeFile << struct2->day << " " << struct2->month << " " << struct2->value << endl;
- writeFile.close();
- }
- /*
- vector <string> fileInput() {
- vector <string> fileInput;
- string buffer;
- ifstream readFile;
- readFile.open("file.txt");
- while (readFile >> buffer) {
- fileInput.push_back(buffer);
- }
- readFile.close();
- return fileInput;
- }
- void printFile(vector <string> fileInput) {
- for (auto& value : fileInput) {
- cout << value << " ";
- }
- }
- */
- string* fileInput(int x) {
- string* fileInput = new string[x];
- string buffer;
- ifstream readFile;
- readFile.open("file.txt");
- int i = 0;
- while (readFile >> buffer) {
- fileInput[i] = buffer;
- i++;
- }
- readFile.close();
- return fileInput;
- }
- void printFile(string* fileInput,int x) {
- for (int i = 0; i < x; i++) {
- cout << fileInput[i] << " ";
- }
- }
- int main() {
- cout << "LiczbaElementow";
- int x; cin >> x;
- writeToFile();
- printFile(fileInput(x),x);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement