Input/Output help

I am at a point that I have no idea what to do. See my code below. The program will not open my mail.dat file that I am supposed to use to get the output of just the email address's on it that outputs to another file "address.dat" I think my code is right but I get nothing, any advice, thanks


// This programs outputs email address's that have the "@" symbol in them

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

using namespace std;

int main()

{
ifstream inData;
string tempString;
ofstream outData;

// Open Data Files
inData.open("mail.dat");
outData.open("adresses.dat");
// Press enter to get the output to an external file
cout << "Please press enter for email address's" << endl;

// Test if file is there
if (!inData)
{
cout << "If mail.dat can not be found program will close" << endl;
cin.get();
cin.get();
return 1;
}

while(inData)

{
inData >> tempString;
if(tempString.find('@') != string::npos);
outData<<tempString;
}

// Output Results
outData << "Email addresses:" << endl;

// Close Files
inData.close();
outData.close();

cin.get();
cin.get();
return 0;
}
if you do this:

inData.open("mail.dat");

you're trying to open that file from the current path. So you need to know where the current path is. Usually somwhere near the .exe (if it's windows)
Topic archived. No new replies allowed.