Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   input/output - using dat files (http://www.go4expert.com/forums/input-output-using-dat-files-t942/)

VickieQuirk 28Jun2006 00:38

input/output - using dat files
 
I need help with the following assignment. I just can't seem to get it to work? It will create the address file but it doesn't put anything in the file. It just creates an empty file.
If anyone can tell me what I am doing wrong I will be forever grateful..

Ok, here's the assignment:
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.
Here is what mail.dat has in it:
---------------------------------------------------------------------------
From: kadcock@clevelandstatecc.edu
Date: June 4, 2005

To: Joe_student@tbrschool.edu

Joe,

Hope you have a good semester.

Regards,
Ken Adcock
---------------------------------------------------------------------------
Here is what I have done:
Code: CPP

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

using namespace std;

int main()
{
   
    ifstream inFile;
    ofstream outFile;
    string tempString;
   
   
    inFile.open("mail.dat");
    outFile.open("addresses.dat");
   
    while(inFile)
    {
        inFile>>tempString;
        if(tempString.find('@')!=string::npos)
            outFile<<tempString;
       
    }
   
    inFile.close();
    outFile.close();
    return 0;
}


shabbir 28Jun2006 10:33

Re: input/output - using dat files
 
Duplicate of input/output - using dat files. Thread closed.


All times are GMT +5.5. The time now is 09:59.