473,326 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Weird Question

Hi,
I'm not verry good at c++ but I was asking myself this question... Could it
be possible to store a variable into a file and load it back into the same
variable? What I would like to do is save a structure into a file so I can
load it back the next time my program run into the same structure.

Thanks, Max.
Jul 19 '05 #1
2 2194
"Maximus" <ik*********@videotron.ca> wrote...
I'm not verry good at c++ but I was asking myself this question... Could it be possible to store a variable into a file and load it back into the same
variable? What I would like to do is save a structure into a file so I can
load it back the next time my program run into the same structure.


It is entirely possible and, as a matter of fact, used by many applications
to keep track of user preferences, for example. Some kind of structure (or
an array thereof) is read from the settings file (if it exists) and at the
end of the run (before quitting) saved into the same file...

The simplest way to deal with incompatibilities is to save your structure
in text form, BTW.

Victor

Jul 19 '05 #2
On Tue, 11 Nov 2003 22:09:12 -0800, Maximus <ik*********@videotron.ca>
wrote:
Hi,
I'm not verry good at c++ but I was asking myself this question... Could
it
be possible to store a variable into a file and load it back into the
same
variable? What I would like to do is save a structure into a file so I
can
load it back the next time my program run into the same structure.

Thanks, Max.

Most complicated thing is to remember the name of the file, so let's call
it remember.dat
write some stuff to the file:

struct POD {... }; // something in there, no pointers !
POD data;

#include <fstream>
ofstream os("remember.dat"); // creates a file to remember
os.write((const char*)&data,sizeof(POD));
If you want to read this back
POD data;

#include <fstream>
ifstream is("remember.dat"); // opens the data
is.read((char*)&data,sizeof(POD));

--
grzegorz
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Robert Schott | last post by:
Hi .. this is for sure the 1k question on fopen but maybe can someone tell me this weird staff if i'm writing: $H = fopen($value,"r"); while(!feof($H)) { $string = fgets($H,1024); .... .......
1
by: Jim Dawson | last post by:
I was writing a subroutine to extract fields from lines of text when I ran into an issue. I have reproduced this error on Perl 5.8 on AIX, 5.8 on Linux and 5.6 on Windows. ############### CUT...
2
by: holgeradelmann | last post by:
Can anyone help please: I found a nice article on the web how to write my dynamice information into an RSS-XML. But I cannot get the code to work. The problem is so simple but weird....
1
by: Pelle | last post by:
Hello all, I have to admit, that the idea that occurred to me recently is weird. It was somehow inspired by the huge response on the "delete operator" thread, but goes into a somewhat different...
82
by: nobody | last post by:
Howdy, Mike! mikecoxlinux@yahoo.com (Mike Cox) wrote in message news:<3d6111f1.0402271647.c20aea3@posting.google.com>... > I'm a C++ programmer, and have to use lisp because I want to use >...
5
by: John Kiernan | last post by:
Hey JavaScript gurus! Here's a weird one: If I check (with an alert) this line: vStrDate2 = vDate.toLocaleString(); I get: Saturday, August 14, 2004 7:57:30 PM (as I should) but this...
0
by: Greenwich Support | last post by:
Hi All, I have a very weird problem which is occurring with a VB.Net app and PostgreSQL 7.3.1. There is a form that has a standard .Net datagrid on it that contains some data from a table in...
5
by: marcmc | last post by:
Is it in any way possible to have a sProc called and executed within SQLServer return its return value to an open .Net Vb application? As a programmer I beleive this can be done and if I wreck my...
2
by: carlos123 | last post by:
im pretty new to java. this might sound like a weird question but! how do i add this code class FileWrite { public static void main(String args) { try{ // Create file ...
2
by: Drupan c | last post by:
Hello everybody i have a weird question... if u guys have observed when we use ms sql .. on the query box when we take the mouse pointer to the corner of a single line...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.