SHOW:
|
|
- or go back to the newest paste.
| 1 | - | // Task: This program finds and email address from incoming forlder called mail.dat and uploads it to a file called addresses.dat. |
| 1 | + | #include <fstream> |
| 2 | - | // |
| 2 | + | // using std::ofstream, std::ifstream |
| 3 | - | // |
| 3 | + | #include <iostream> |
| 4 | // using std::cerr | |
| 5 | - | #include <iostream> // including the iostream |
| 5 | + | |
| 6 | // using std::string | |
| 7 | - | #include <iomanip> |
| 7 | + | |
| 8 | - | #include <fstream> // including the fstream for files |
| 8 | + | int main() |
| 9 | {
| |
| 10 | - | using namespace std; |
| 10 | + | std::ifstream emails("mail.dat");
|
| 11 | std::ofstream addresses("addresses.dat");
| |
| 12 | - | int main () |
| 12 | + | if(! (emails && addresses)) {
|
| 13 | std::cerr << "Error opening" << std::endl; | |
| 14 | return 1; | |
| 15 | - | ifstream emails; // declaring this as emails file stream |
| 15 | + | } |
| 16 | - | ofstream addresses; // Declaring the output for addresses |
| 16 | + | for(std::string word; emails >> word; ) {
|
| 17 | - | |
| 17 | + | if(word.find('@') == std::string::npos)
|
| 18 | - | emails.open("mail.dat"); //opening the file stream mail.dat
|
| 18 | + | continue; // not a mail |
| 19 | - | addresses.open("addresses.dat"); //opening the file stream addresses.dat
|
| 19 | + | std::string::size_type last_n = word.length() - 1; |
| 20 | - | |
| 20 | + | char last = word[last_n]; |
| 21 | - | string oneChar ; //declaring a string of characters called |
| 21 | + | if(last == '>' || last == ',') |
| 22 | - | // onechar |
| 22 | + | word.erase(last_n); |
| 23 | if(word[0] == '<') | |
| 24 | - | string correct; // declaring correct as the final correct string |
| 24 | + | word.erase(0, 1); |
| 25 | - | // output |
| 25 | + | if(! (addresses << word).put('\n')) {
|
| 26 | std::cerr << "Error writing" << std::endl; | |
| 27 | - | char at = '@'; // declaring @ as a char |
| 27 | + | return 1; |
| 28 | } | |
| 29 | - | while(emails) // doing a while loop to scan the documents |
| 29 | + | } |
| 30 | - | {
|
| 30 | + | return 0; |
| 31 | - | if (oneChar.find(at) != string::npos) // if string is not equal to '@' then do |
| 31 | + |