Solved

Saving files.....

Posted on 2000-04-07
5
173 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

832 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