need help with Looping

I am not sure if I understand the Assignment completely.When I wrote the Program it would open the file and also extract the email onto the other file. However, it would not print the Email or extracted Email addresses on the compiler. I've been working on this for last 2 days, my head is smoking.
You're working for a company that's building an email list from files of mail messages. They would like you to write a program that reads a file called mail.dat, and that outputs every string containing the @ sign to file addresses.dat. For the purpose of this project, a string is defined as it is by the C++ stream reader - a contiguous sequence of non-whitespace characters.
This is what I got 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
#include <iostream>
#include <fstream> 
#include <string>
using namespace std;

int main()
{
string eMail;
ifstream inData;
ofstream outData;

inData.open("D:mail.dat");
outData.open("D:addresses.dat");
	
	if (!inData)
	{
	cout << "Can't open mail.dat file"<< endl;
	cin.get();
	return 1;
	}

	while (inData)
	{
	cout << eMail;
	inData>> eMail;
	if(eMail.find('@')!=string::npos)
	outData << eMail << endl;
	}
		
	inData.close();
	outData.close();
	cin.get();
	return 0;
	}


The problem is the Compiler showes he mail.dat like this:
ken.smith@gmail.comexmapleofisherefrom:betty@hotmail.comto:kadcockclevelandstatecc.youknownomoreemail
It is not printing the white spaces.Also I have not figured out how the complier, prints out the data from the address.dat. I really hope you can help me. Thanks
Last edited on
The compiler doesn't have anything to do with the format of mail.dat. If you're referring to the output you display on cout, no.. that won't have spaces. The extraction operator skips all whitespace by default.

Looks like it should do what you want it to, provided mail.dat is formatted correctly. Have you opened up addresses.dat and looked to see what was in it?

Last edited on
Thank you for your replie. In that case, the program does extract the Email addresses correctly and puts them into the addresses.dat. I did check it several times and it all seems to work. Thank you for your help.
Topic archived. No new replies allowed.