Advertisement
Alberts00

virkne3.cpp

Jan 11th, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8.     char a[251];
  9.     char b[251];
  10.      {
  11.             ifstream ifile;
  12.             ifile.open("virkne3.in", ifstream::in);
  13.             if( !ifile.is_open( )) {
  14.                         cout << "Nevar atvert failu virkne3.in" << endl;
  15.                         system("PAUSE");
  16.                         return 255;
  17.             } else {
  18.                         cout << "Fails atverts veiksmiigi" << endl;
  19.             }
  20.             while(ifile.good()) {
  21.                         ifile >> a;
  22.                         cout <<"Ievadiitaa fraaze: "<< a << endl;
  23.             }
  24.      }
  25.  char last = '0';
  26.  int tpos = 0;
  27.  for(unsigned int i = 0; i < strlen(a); i++)
  28.  {
  29.   if( (last != a[i]) ) { b[tpos++] = a[i]; last = a[i]; }
  30.  }
  31.  b[tpos] = '\0';
  32.  
  33.  cout << "Labojums:" << b << endl;
  34.  
  35.       {
  36.   ofstream myfile ("virkne3.out");
  37.   if (myfile.is_open())
  38.   {
  39.     myfile << b;
  40.     cout << "Labojums veiksmigi ievadiits faila virkne3.out" <<endl;
  41.     myfile.close();
  42.   }
  43.   else cout << "Nevar atvert failu.";
  44. }
  45.     system("PAUSE");
  46.     return EXIT_SUCCESS;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement