Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6. /**
  7.  * Funkcja ignoruje napotkane białe znaki w strumieniu
  8.  * zwraca liczbę usuniętych znaków z strumienia
  9.  */
  10. int ignoreWhiteMarks(istream& in) {
  11.     int howMany = 0;
  12.     while (in.peek() == 10 || in.peek() == 32)
  13.         in.ignore();
  14.     return howMany;
  15. }
  16. int main() {
  17.     int value;
  18.     char what;
  19.     string str;
  20.     filebuf* fb = new filebuf();
  21.     fb->open("plik.tmp", ios::in);
  22.     istream plik(fb);
  23.     while (!plik.eof()) {
  24.         ignoreWhiteMarks(plik);
  25.         what = plik.peek(); //podglądamy co jest w strumieniu
  26.         if (isdigit(what)) {
  27.             plik>> value;
  28.             cout <<"Liczba: " <<value <<endl;
  29.         } else {
  30.             plik>> str;
  31.             cout <<"Nie liczba: " <<str <<";" <<endl;
  32.         }
  33.     }
  34.     fb->close();
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement