having trouble with this
"You're working for a company that's building an email list from files of mail messages. They would like you to write a program that reads a file called mail.dat, and that outputs every string containing the @ sign to file addresses.dat. For the purpose of this project, a string is defined as it is by the C++ stream reader-a contiguous sequence of non-whitespace characters.
Given the data:
From: sharon@marzipan.edu
Date: Wed, 13 Aug 2003 17:12:33 EDT
Subject: Re: hi
To: john@meringue.com
John,
Dave's email is dave_smith@icing.org
ttyl,
sharon
Then the program would output on file addresses.dat:
sharon@marzipan.edu
john@meringue.com
dave_smith@icing.org.
Use meaningful variable names, proper indentation, and appropriate comments. Thoroughly test the program using your own data sets.
so far i have this and i am getting the output of:
Date: Wed, 13 Aug 2003 17:12:33 EDTTo: john@meringue.com
which is not correct at all it did give me one of the emails but i dont know why it gave me the date and not the other two emails.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include "stdafx.h"
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
// Definitions
ifstream infile;
ofstream outfile;
string Email;
const char AT = '@';
char exit_char;
// File Test
infile.open("mail.dat");
if (!infile) // Checks to varify if the input file is valid
{
cout << endl << " *** Error: Can not open the input file ***"
<< endl << endl << endl;
cout << "Enter any key to end execution of this program . . . ";
cin >> exit_char;
return 1;
}
outfile.open("addresses.dat");
if (!outfile) // Checks to varify if the output file is valid
{
cout << endl << " *** Error: Can not find the output file ***"
<< endl << endl << endl;
cout << "Enter any key to end execution of this program . . . ";
cin >> exit_char;
return 1;
}
// Program
cout << "Mail Extractor" << endl << endl << endl; // Title
while(getline (infile, Email))
{
cout << Email << endl;
if(Email.find('AT')!=string::npos)
outfile<<Email;
}
// Exit
cout << endl << endl << endl;
cout << "Press any key then enter to exit ";
cin >> exit_char;
return 0;
}
|