我必须编写一个程序,从文件中提取电子邮件地址并将其放入另一个文件中。我不知道如何让程序将信息放入另一个文件。另外,我是否必须像创建第一个文件一样创建第二个文件?这是我到目前为止所拥有的:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
char chr;
int main()
{
string mail;
ifstream inFile; //this is the file that we will get the information from
ofstream outfile; // this is the file that the data will be saved in
inFile.open("mail.dat"); // this will open the file with the original informations
outfile.open("addresses.dat"); // this will open the file where the output will be
while (inFile)
{
cin>>mail;
mail.find('@')!=string::npos; //this finds the email addresses
}
inFile.close(); // this will close the file when we are done with it
outfile.close();
cin>>chr;
return 0;
}