Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Saving to a file

Reply
Thread Tools

Saving to a file

 
 
Roy Gourgi
Guest
Posts: n/a
 
      07-17-2005
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


 
Reply With Quote
 
 
 
 
sun.aries@gmail.com
Guest
Posts: n/a
 
      07-17-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IDE very slow when saving file Chad A. Beckner ASP .Net 6 12-24-2005 11:27 PM
EXCEL question saving a file saving the the first column as read only Luis Esteban Valencia ASP .Net 0 01-06-2005 07:02 PM
Saving DataTable to session vs saving a Custom object. John Kandell ASP .Net 4 12-10-2004 05:08 AM
Saving a variable to a text file? Kwaj VHDL 1 02-27-2004 07:31 AM
Saving Images While Saving ASP Pages ! Lovely Angel For You ASP General 1 10-03-2003 12:03 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57