Advertisement
homer512

Sina's assigment

Mar 19th, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <fstream>
  2. // using std::ofstream, std::ifstream
  3. #include <iostream>
  4. // using std::cerr
  5. #include <string>
  6. // using std::string
  7.  
  8. int main()
  9. {
  10.   std::ifstream emails("mail.dat");
  11.   std::ofstream addresses("addresses.dat");
  12.   if(! (emails && addresses)) {
  13.     std::cerr << "Error opening" << std::endl;
  14.     return 1;
  15.   }
  16.   for(std::string word; emails >> word; ) {
  17.     if(word.find('@') == std::string::npos)
  18.       continue; // not a mail
  19.     std::string::size_type last_n = word.length() - 1;
  20.     char last = word[last_n];
  21.     if(last == '>' || last == ',')
  22.       word.erase(last_n);
  23.     if(word[0] == '<')
  24.       word.erase(0, 1);
  25.     if(! (addresses << word).put('\n')) {
  26.       std::cerr << "Error writing" << std::endl;
  27.       return 1;
  28.     }
  29.   }
  30.   return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement