Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Saving files.....

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

839 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