Thread: using file iostream....

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    26

    using file iostream....

    okay, here's my main...messy, I know, I've tried so much stuff to get it to run:

    Code:
    void main()
    {
        int i = 0;
        ifstream fin("EmailTest.txt");
        char s[300];
        char* str = s;
        MyString String(str);
    
    
        while( !fin.eof )
        {
            fin >> str;
    
            cout << str;
                
            Email anEmail( str );
    
    	        if( anEmail.IsValid() )
    	    	    cout << 1 << endl;
    	        else
    	    	    cout << 0 << endl;
          
    
        }
    }

    Here's what it needs to do: In your main() make a loop that would read file stream with email addresses and output file stream with 0 or 1 strings one per line.


    I have tried so much stuff, and I can't get it to work. I have no idea how to do it...especially since it's a custom string class...

    EDIT: I know the file output isn't there...I'm trying to get the input to work first...
    Last edited by Saggio; 10-05-2006 at 01:46 AM.

  2. #2
    Registered User
    Join Date
    Aug 2006
    Posts
    74
    Hello there. It makes things a little less clear when you post some code, but give no clue as to your errors and there are a lot of people on these boards that will go berserk and curse you out about it. Anyways here is a brief program that will retrieve emails from a file, which is basically the same as your code:

    Code:
    #include <fstream>  // This is required for file streams.
    #include <iostream> // This is required for input/output streams. (ie cout)
    
    int main()
    {
      std::ifstream emailFile("Emails.txt"); // Open a file for inputing.
      char s[300];
      char* str = s; // A little redundant considering the above line is sufficient for storing input from a file, but will work nontheless.
      
      while(!emailFile.eof())  // Notice eof is a function
      {
        emailFile >> str;  // Read a line from the file.
        std::cout << str << std::endl;  // Output the line just read to the screen.
      } 
      
      emailFile.close();   // All done so close the file.
      
      return 0;
    }
    Hopefully the above is enough to get you on your way. Output to a file is rather similar to input, but instead of an ifstream you use ofstream.
    Last edited by Kurisu33; 10-05-2006 at 03:47 AM.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    26
    Sorry about that, the problem is that it does not seem to be getting the input from the file correctly. It doesn't work with the code you posted, either.


    EDIT: Oh wow, the whole problem was that it was named EmailTest.txt.txt....damn Windows for hiding extensions! haha

    hours of aggrivation for THAT.

    thanks.
    Last edited by Saggio; 10-05-2006 at 07:38 AM.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Now is the time to disable extension hiding. It's one of the stupidest "features" of Windows anyway.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    26
    Yeah, I usually turn it off, but I just installed the windows vista beta last week, looks like I forgot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  5. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM