It compiles then reads the file and says there is only 1 email but there is really 40.
Well then there's probably something wrong with the code that checks for duplicate emails, since the first email was correctly identified.
This line in the for loop is useless, since any emails that have been added are already lowercased:
Code:
transform(b.begin(), b.end(), b.begin(), toLower());
Code:
fin.open(ifile.c_str());
if(!fin.good()) throw "I/O error";
if(ifile.empty())
fin.open("fileContainingEmails.txt");
Opening the file "" will likely fail, and so your code there would never get a chance to execute. I'd put it first and put the ordinary opening code in an else clause.
[edit]
Code:
anEmail = line.substr(s, (e - s) + 1);
That probably doesn't sdo what you want, as s is always equal to i-2 and e to i+2.
You probably meant to put this code in a loop of some sort.
Code:
s = i - 1;
if(s < 0) break;
bool valid1 = false;
if(line[s] >= 'a' && line[s] <= 'z')valid1 = true;
if(line[s] >= 'A' && line[s] <= 'Z')valid1 = true;
if(line[s] >= '0' && line[s] <= '9')valid1 = true;
if(line[s] == '_' || line[s] == '+' || line[s] == '-')valid1 = true;
if(valid1 == true)s--;
if(vaild1 == false)break;
Note that if you did the line in red would have to be executed only once. [/edit]