Saving to a file

Discussion in 'C++' started by Roy Gourgi, Jul 17, 2005.

  1. Roy Gourgi

    Roy Gourgi Guest

    Hi,

    I am trying to save information onto a file, but I have to have it print on
    the screen first and then I would like to save it into the file. The problem
    is that the information that I print on the screen is a bit different than
    what is saved onto the file, but when I try to save it into a file, it saves
    what is printed on the screen and not what I have in my SaveFile routine.
    Here is an example of what the problem is in my program:

    main()
    {

    cout << endl << "Line Number " << gnLineNumber << " Part Number " <<
    gnPartNumber;

    SaveFile();
    stream=freopen("CON", "w", stdout);

    }

    SaveFile()
    {

    if((stream = freopen("aOutput.cpp", "a", stdout)) == NULL) exit(-1);

    cout << endl << " Model Number " << gnModelNumber << " Line Number " <<
    gnLineNumber << " Part Number " << gnPartNumber;
    }

    Instead of it printing what is in the SaveFile routine, it prints what is in
    the main program in my aOutput file. What am I doing wrong?

    TIA
    Roy
     
    Roy Gourgi, Jul 17, 2005
    #1
    1. Advertising

  2. Roy Gourgi

    Guest

    Are you sure you get what is in the main program in your aOutput file?

    I tried it with the following codes and what I got in my aOutput is
    what is in the Savefile routine:
    ---------------------------------------------------------
    FILE * stream;
    int gnModelNumber = 300;
    int gnLineNumber = 400;
    int gnPartNumber = 500;
    void SaveFile()
    {
    if((stream = freopen("aOutput.cpp", "a", stdout)) == NULL) exit(-1);

    cout << endl
    << " Model Number "
    << gnModelNumber
    << " Line Number "
    << gnLineNumber
    << " Part Number "
    << gnPartNumber;
    }

    int main(int argc, char* argv[])
    {
    cout << endl
    << "Line Number "
    << gnLineNumber
    << " Part Number "
    << gnPartNumber;


    SaveFile();
    stream=freopen("CON", "w", stdout);

    return 0;
    }
    --------------------------------------------------------------------------------

    Aries Sun
     
    , Jul 17, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kwaj
    Replies:
    1
    Views:
    442
    Grigorios Angelis
    Feb 27, 2004
  2. Chad A. Beckner

    IDE very slow when saving file

    Chad A. Beckner, Dec 24, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    583
    Ray Cassick \(Home\)
    Dec 24, 2005
  3. John Kandell
    Replies:
    4
    Views:
    4,188
    eeebop
    Dec 10, 2004
  4. Luis Esteban Valencia
    Replies:
    0
    Views:
    2,536
    Luis Esteban Valencia
    Jan 6, 2005
  5. Lovely Angel For You

    Saving Images While Saving ASP Pages !

    Lovely Angel For You, Oct 2, 2003, in forum: ASP General
    Replies:
    1
    Views:
    220
    Curt_C [MVP]
    Oct 3, 2003
Loading...

Share This Page