help with streams

This is a discussion on help with streams within the C++ Programming forums, part of the General Programming Boards category; can anyoe tell me whats wrong with this and if im on the right track. i need to make a ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    230

    help with streams

    can anyoe tell me whats wrong with this and if im on the right track. i need to make a program that displays a piece of advice to the user when they run the program. then it allows them to add some advice to the file and then it ends. the next time it runs it allows the next person toa dd more advice after it display the old advice. get it. heres what i have so far. plz give me some psuedocode to get me going.
    Code:
     // This program will allow the user to add advice to a file 
    // already made by the programmer
    #include <iostream>
    #include <fstream>
    #include <cstdlib>
    using namespace std;
    void editfile (ifstream& in_stream, ofstream& out_stream);
    
    int main()
    {
    	ifstream advFileIn;
    	ofstream advFileOut;
    
    	cout << "Welcome to advice master. "<<endl;
    
    	advFileIn.open("advice.txt");
    	if (advFileIn.fail())
    	{
    		cout << "Error opening file"<<endl;
    		cout << "Program is terminating"<<endl;
    		exit(1);
    	}
    	
    	advFileOut.open("outadvice.txt");
    	if (advFileOut.fail())
    	{
    		cout << "Error opening file"<<endl;
    		cout << "Program is terminating"<<endl;
    		exit(1);
    	}
    
    	editfile(advFileIn, advFileOut);
    
    	return 0;
    }
    
    void editfile(ifstream& in_stream, ofstream& out_stream)
    {}
    NOTE this is not homework.
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    All you're doing is adding? Open it for appending then.

    Open the file for reading (or updating), and display the contents.
    Close the file (or leave it open if you've opened it for updating) and open it for appending.
    Write the data.
    Close the file.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing to two streams: va_arg issues
    By dwks in forum C Programming
    Replies: 2
    Last Post: 09-26-2007, 10:14 AM
  2. input/output streams
    By cybernike in forum C++ Programming
    Replies: 2
    Last Post: 08-07-2007, 11:15 PM
  3. Independent streams of pseudo random number generator
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-15-2001, 04:32 AM
  4. File Streams, new error on me.
    By Eber Kain in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2001, 07:28 PM
  5. Replies: 4
    Last Post: 10-16-2001, 02:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21