Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Task: This program finds and email address from incoming forlder called mail.dat and uploads it to a file called addresses.dat.
- //
- //
- #include <iostream> // including the iostream
- #include <string>
- #include <iomanip>
- #include <fstream> // including the fstream for files
- using namespace std;
- int main ()
- {
- ifstream emails; // declaring this as emails file stream
- ofstream addresses; // Declaring the output for addresses
- emails.open("mail.dat"); //opening the file stream mail.dat
- addresses.open("addresses.dat"); //opening the file stream addresses.dat
- string oneChar ; //declaring a string of characters called
- // onechar
- string correct; // declaring correct as the final correct string
- // output
- char at = '@'; // declaring @ as a char
- while(emails) // doing a while loop to scan the documents
- {
- if (oneChar.find(at) != string::npos) // if string is not equal to '@' then do
- // following code
- {
- if(oneChar.at(oneChar.length() -1 ) == ',') //if it has a comma
- {
- oneChar.substr(0, oneChar.length() - 1); //remove comma
- }
- addresses << correct << endl; // output the corrected email address to outdata
- }
- emails >> oneChar;
- }
- emails.close(); //closing emails filestream
- addresses.close(); //closing addresses filestream
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment