Holland

Untitled

Oct 10th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib> // voor exit
  4. using namespace std;
  5.  
  6. int main ( )
  7. {
  8.     ifstream invoer;
  9.     ofstream uitvoer;
  10.     char kar;
  11.     invoer.open ("invoer.txt",ios::in);
  12.     if ( ! invoer )
  13.     {
  14.         cout << "File niet geopend" << endl;
  15.         exit (1);
  16.     } // if
  17.        
  18.     char prevkar = -1;
  19.     uitvoer.open ("uitvoer.txt",ios::out);
  20.     kar = invoer.get ( );
  21.     int k = 1;
  22.    
  23.     while (!invoer.eof())
  24.     {
  25.         if(kar==prevkar)
  26.             k++;
  27.         else
  28.         {
  29.             if(prevkar!='\n' && prevkar!='\r' && k>1)
  30.             {
  31.                 cout << "{" << k << "}";
  32.                 cout << kar;
  33.             }
  34.             else cout << kar;
  35.             k = 1;
  36.         }
  37.  
  38.         prevkar = kar;
  39.         kar = invoer.get();
  40.     } // while
  41.        
  42.     invoer.close ( );
  43.     uitvoer.close ( );
  44.     return 0;
  45. } // main
Advertisement
Add Comment
Please, Sign In to add comment