Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Kolokwium.cpp : Ten plik zawiera funkcję „main”. W nim rozpoczyna się i kończy wykonywanie programu.
- //
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- using namespace std;
- struct para {
- double x, y;
- para(double _x, double _y);
- };
- para::para(double _x, double _y) {
- x = _x;
- y = _y;
- };
- para createPara();
- void saveToFile(vector<para> vector, int size);
- void readFromFile();
- int main()
- {
- setlocale(LC_ALL, "pl_PL");
- vector<para> w;
- for (int i = 0; i < 3; i++) {
- w.push_back( createPara() );
- }
- saveToFile(w, 3);
- readFromFile();
- system("PAUSE");
- return 0;
- }
- para createPara() {
- double a, b;
- cout << "Wprowadz parę liczb\n";
- cin >> a >> b;
- para p(a, b);
- return p;
- }
- void saveToFile(vector<para> vector, int size) {
- ofstream file("text.txt", ios::out);
- for (int i = 0; i < size; i++) {
- file << vector[i].x << " " << vector[i].y << " ";
- }
- file.close();
- }
- void readFromFile() {
- string buffer;
- ifstream file("text.txt");
- if (!file.good()) cout << "Nie udało się otworzyć pliku!\n";
- else while (!file.eof()) {
- getline(file, buffer);
- cout << buffer << " ";
- }
- file.close();
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement