Solved

Saving files.....

Posted on 2000-04-07
5
172 Views
Last Modified: 2010-04-02
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
Comment
Question by:anita177
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:ajitm
ID: 2692918
can you make the things more clear?
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2692968
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
 
LVL 1

Expert Comment

by:tvanceplus
ID: 2693873
look at a function called atexit()
this should be called when your programs exits.

Good Luck!
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2699440
>> atexit

This is the C++  topic area ;)
0
 
LVL 1

Accepted Solution

by:
tvanceplus earned 10 total points
ID: 2701193
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now