hi, i am extracting email addresses from file code is compiled successfully but when i enter file name this give unknown error can u help me people plz
this is the code
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main()
{
string filename;
cout<<" Enter filename : ";
cin>>filename;
int atpos,dotpos,no_of_inst=0,i;
string emailAdd,instName;
ifstream fin;
fin.open(filename.c_str());
string listofinst[50];
bool repeated=false;
fin>>emailAdd;
while(!fin.eof() && no_of_inst<50)
{
atpos=emailAdd.find("@");
dotpos=emailAdd.find(".",atpos);
instName=emailAdd.substr(atpos,dotpos-atpos-1);
if(no_of_inst==0)
{
listofinst[no_of_inst]=instName;
no_of_inst=no_of_inst+1;
}
else
{
for(i=0;i<no_of_inst;i++)
{
if(listofinst[i]==instName)
{
repeated=true;
}
}
if(repeated==false)
{
listofinst[no_of_inst]=instName;
no_of_inst=no_of_inst+1;
}
}
fin>>emailAdd;
}
fin.close();
this line is where the error accures, when the file is not actually opened or if the function find cant find.
atpos and dotpos will be equal to (-1).
as suggested by coder777, try add some checks to see that the file is opend and that the data is beeing red correctly, work with a debugger (or output to the screen some of the content of variables to see what is happening, if you cant use the debugger.)
check the values returned by the find() function to see if anything was actually found.