i am currently new to c++ coding and i have been working on this code for a class, i am suppose to get emails from a .txt file and the program reads each line of the file analyzing each and every char of every line to see if it is a valid email address. for example: [email]johndoe@yahoo.com[/email] = valid
, [email]john@doe@yahoo.com[/email] = invalid
.
right now im having trouble getting the program to process each line and print to the console the valid email address only.
any help would be great. thanks.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream fin;
ofstream fout;
string line;
string inputemail;
cout << "Enter input filename [default: fileContainingEmails.txt]: ";
getline(cin, inputemail);
fin.open(inputemail.c_str());
cout << endl;
string Emails;
int i;
while (getline(fin, Emails))
{
for (i = 0; i < Emails.length(); i++)
{
if (Emails[i] == '@')
{
cout << Emails[i] << endl;
} // if
} // for
} // while
cout << endl;
// output file section
string outputemail;
cout << "Enter output filename [default: copyPasteMyEmails.txt]: ";
getline(cin, outputemail);
fout.open(outputemail.c_str());
fin.close();
fout.close();
cout << endl;
cout << "Input File: " << inputemail << endl;
cout << "Output file: " << outputemail << endl;
return 0;
}