Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Saving files.....

Posted on 2000-04-07
5
Medium Priority
?
179 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
[X]
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
  • 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 30 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 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 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.
Suggested Courses

604 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