Mar 7, 2016 at 12:08am UTC
I have no clue what is wrong with this code. The only output I get is the last email address from mail.dat, this is due tomorrow please help.
mail.dat =
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
my only output is: dave_smith@icing.org
it needs to be:
The file Mail.dat contains the following e-mail addresses:
sharon@marzipan.edu
john@meringue.com
dave_smith@icing.org
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
int pos;
int lens1;
string s1;
string email;
ifstream indata;
ofstream outdata;
indata.open("D:\\mail.dat");
outdata.open("D:\\list.dat");
if (!indata)
cout << "The file mail.dat cannot be opened" << endl;
if (!outdata)
cout << "The file list.dat cannot be opened" << endl;
if (indata.is_open())
{
while (!indata.eof()) // read the entire file including white space till the end of the file
indata >> s1;
pos = s1.find("@"); // find the "@" in the string
lens1 = s1.size(); // find the size of the string
if (pos <= lens1 && pos>lens1) // if the "@" character is within the measured string then cout as s1
cout << "The file Mail.dat contains the following e-mail addresses: " << endl;
cout << s1 << endl;
outdata << s1;
cin.get();
}
{
indata.close();
outdata.close();
}
return 0;
}
Mar 7, 2016 at 11:36pm UTC
It worked great! Thank you so much for your help!