Guest User

Untitled

a guest
Mar 19th, 2014
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Task: This program finds and email address from incoming forlder called mail.dat and uploads it to a file called addresses.dat.
  2. //
  3. //
  4.  
  5. #include <iostream>                         // including the iostream
  6. #include <string>
  7. #include <iomanip>
  8. #include <fstream>                          // including the fstream for files
  9.  
  10. using namespace std;
  11.  
  12. int main ()
  13.  
  14. {
  15.     ifstream emails;                        // declaring this as emails file stream
  16.     ofstream addresses;                     // Declaring the output for addresses
  17.    
  18.     emails.open("mail.dat");                //opening the file stream mail.dat
  19.     addresses.open("addresses.dat");            //opening the file stream addresses.dat
  20.    
  21.     string oneChar ;                        //declaring a string of characters called
  22.                                             // onechar
  23.  
  24.     string correct;                         // declaring correct as the final correct string                                                   
  25.                                     // output
  26.  
  27.     char at = '@';                          // declaring @ as a char
  28.  
  29.     while(emails)                           // doing a while loop to scan the documents      
  30.     {
  31.      if (oneChar.find(at) != string::npos)  // if string is not equal to '@' then do
  32.                                             // following code
  33.      {
  34.          if(oneChar.at(oneChar.length() -1 ) == ',')    //if it has a comma
  35.          {
  36.              oneChar.substr(0, oneChar.length() - 1);   //remove comma
  37.          }
  38.  
  39.      addresses << correct << endl;          // output the corrected email address to outdata
  40.      
  41.      }
  42.      emails >> oneChar;
  43.     }
  44.     emails.close();                         //closing emails filestream
  45.     addresses.close();                      //closing addresses filestream
  46.    
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment