Question: Hello, I'm trying to read a file that has some emails in it. I have to extract the emails only without anything else in the
Hello,
I'm trying to read a file that has some emails in it. I have to extract the emails only without anything else in the file. I'm using this code to do so, however, it's giving me a run time error. The reason I get this error is if I have any other number than 1 in the function where I extract the substring, this one in specific:
line=line.substr(location+7);
location is an integer that has the index of the character I search for. Note that I can't change the tag I'm searching for to one chararcter only since the file may have any tag. The problem is resolved if I do this one time only without the loop. But I need the loop to read all lines in the file.
For example, if the file has:
Send email
Send email
Send email
And this is the code I'm using to extract the emails:
#include
int main(){ ifstream in_stream; string line; int location;
in_stream.open("emails.txt"); getline(in_stream, line); while (!in_stream.eof()) { location= line.find("mailto:"); line=line.substr(location+7); //this one is causing the run time error, I can't have location+1, I need a way to have it as is line=line.substr(0, line.find("\"> Send")); cout<< line<
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
