Searching a file

hey guys!

My first post! yay for me haha...

I am taking a c++ class this semester and I am having trouble with an assignment. You have probably seen it before...

I requires me to write a program that reads a file, extracts only the email addresses from the file, and writes them to another file. I can read the file ok, but when it writes to my output file, it is writing the entire contents of the input file in one big long string, not just the email addresses like I need.

Below is my code I have so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <fstream>;			// For File I/O
#include <iostream>;		// For cout, endl
#include <string>;
using namespace std;		

int main()
{
ifstream inFile;
ofstream outFile;
string Address;


//Open Input File
inFile.open("mail.dat");

//Check for input file
if(!inFile)
{
cout << "No Input File Was Found" <<  endl;
cin.get();
cin.get();
return 1;
}

//Open Output File
outFile.open("Addresses.dat");

//Check for output file
if(!outFile)
{
cout << "No Output File Was Found" <<  endl;
cin.get();
cin.get();
return 1;
}

//Output a list of the email addresses contianed in the file.
outFile << "The email addresses are:" << endl;
outFile << "" << endl;
inFile >> Address;
while (inFile)
{
outFile << Address <= "@";
inFile >> Address;
}

//Close I/O Files
inFile.close() ;
outFile.close() ;

// Process is complete
cout << "Process is complete" << endl; 
cout << "" << endl;

// Press any key to continue
system ("pause");
return 0; 

}
Is the mail.dat ONLY emails on there? How is it arranged?
When reading in, you don't check to see that you have an address (a token containing '@') and when writing to your output file you don't separate your tokens with anything. I don't think line 43 is doing what you think it should.
Topic archived. No new replies allowed.