• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

Saving files.....

Hello,

I'm in the process of writing a project in C++ and i have a few text files that need to be saved automatically when the program finishes.. I'm not sure on how to do this.. is there a simple command to do this??? HELP

Thanks
0
anita177
Asked:
anita177
  • 2
  • 2
1 Solution
 
ajitmCommented:
can you make the things more clear?
0
 
KangaRooCommented:
There is no simple (magical) command that will do so.

If you can give some information about how your program holds the text (file) in memory we can help you to write that text to disk.
0
 
tvanceplusCommented:
look at a function called atexit()
this should be called when your programs exits.

Good Luck!
0
 
KangaRooCommented:
>> atexit

This is the C++  topic area ;)
0
 
tvanceplusCommented:
Here is some code to help you do this.

#include <stdlib.h>
#include <fstream.h>

void savefiles();

main(){

 atexit(savefiles);

 return 0;

}


void savefiles(){
 //code to save your files
}


The atexit(void(__cdecl *func)( void ))
function takes a pointer to another function with no parameters. Whenever your program terminates, the function passed to atexit() will be called before any global data is destroyed.

Good Luck!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now