How to find '@" in a string

I have a mail.dat list which contains three different emails and some other comments. I know how to use inFile.open("mail.dat"). What I want to do is use the find command to locate a string that contains'@' and output the three email addresses in to a file called addresses.dat. Does any one know how to code this?

mail.dat file

From:sharon@whoknowswhere.edu
Date: Wed, 13 Aug 2003 17:12:33 EDT
Subject:Re: hi
To:bill@meringue.com
Bill,
John's email is john_smith@icing.org.
ttyl,
sharon


the program would output the following information on file addresses.dat

sharon@whoknowswhere.edu
bill@meringue.com
john_smith@icing.org.

This is what I have so far.

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{

ifstream inFile;
ofstream outFile;


inFile.open("mail.dat");
outFile.open("addresses.dat");

while(inFile)
{









It depends on the format of your base file with the adresses (mail.dat)...

If you know the format, you could read in the lines and search for the @... Or read in every single string or word and also use std::find() or write an own-written function (but i think thats not what you want)

Or you could use regex'es (e.g. std::regex)...
closed account (DSLq5Di1)
http://cplusplus.com/reference/string/getline/
http://cplusplus.com/reference/string/string/

Check the examples of find, find_first_of, last_of, etc.

The "From" and "To" fields shouldn't be a problem, email addresses in the body text may require additional logic to handle grammar and/or typos.
Topic archived. No new replies allowed.