Advertisement
Guest User

Untitled

a guest
May 28th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <fstream>
  5. #include <sstream>
  6. using namespace std;
  7.  
  8. int main(){
  9.     fstream file;
  10.     string text;
  11.  
  12.     //ZAPIS
  13.     cout << "Zapis tektu do pliku" << endl;
  14.     getline(cin, text);
  15.     file.open("myFile.txt", ios::out);
  16.     if (file.is_open()) {
  17.         file << text;
  18.         file.close();
  19.     }
  20.     else {
  21.         cout << "Nie udalo sie otworzyc pliku" << endl;
  22.     }
  23.     cout << endl;
  24.     //ODCZYT
  25.     string loadedStr;
  26.  
  27.     file.open("myFile.txt", ios::in);
  28.     if (file.is_open()) {
  29.             getline(file, loadedStr);
  30.             cout << "Oczytano z pliku:" << endl;
  31.             istringstream iss(loadedStr);
  32.             string word;
  33.             while (iss >> word) {
  34.                 cout << word << endl;
  35.             }
  36.             file.close();
  37.     }
  38.     else {
  39.         cout << "Nie udalo sie otworzyc pliku" << endl;
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement