Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <sstream>
- using namespace std;
- int main(){
- fstream file;
- string text;
- //ZAPIS
- cout << "Zapis tektu do pliku" << endl;
- getline(cin, text);
- file.open("myFile.txt", ios::out);
- if (file.is_open()) {
- file << text;
- file.close();
- }
- else {
- cout << "Nie udalo sie otworzyc pliku" << endl;
- }
- cout << endl;
- //ODCZYT
- string loadedStr;
- file.open("myFile.txt", ios::in);
- if (file.is_open()) {
- getline(file, loadedStr);
- cout << "Oczytano z pliku:" << endl;
- istringstream iss(loadedStr);
- string word;
- while (iss >> word) {
- cout << word << endl;
- }
- file.close();
- }
- else {
- cout << "Nie udalo sie otworzyc pliku" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement