473,326 Members | 2,168 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.

storing a list of struct in a file

Hi all,
I would like to store (and read) a list of structs into a file using c+
+ (each struct contains integers and strings), and I'm wondering if it
there is a method to do it at "high level", I mean: I would like to
don't care of how the strucs are saved on the file, I want to just
save/load my list, is it possible using the std?
Dec 17 '07 #1
5 3077
major a écrit :
Hi all,
I would like to store (and read) a list of structs into a file using c+
+ (each struct contains integers and strings), and I'm wondering if it
there is a method to do it at "high level", I mean: I would like to
don't care of how the strucs are saved on the file, I want to just
save/load my list, is it possible using the std?
There is no such thing in standard but there are many libraries out
there to do it.

See FAQ about serialization:
http://www.parashift.com/c++-faq-lit...alization.html

Michael
Dec 17 '07 #2
On Dec 17, 4:59 am, major <oce...@despammed.comwrote:
Hi all,
I would like to store (and read) a list of structs into a file using c+
+ (each struct contains integers and strings), and I'm wondering if it
there is a method to do it at "high level", I mean: I would like to
don't care of how the strucs are saved on the file, I want to just
save/load my list, is it possible using the std?
On Dec 17, 4:59 am, major <oce...@despammed.comwrote:
Hi all,
I would like to store (and read) a list of structs into a file using c+
+ (each struct contains integers and strings), and I'm wondering if it
there is a method to do it at "high level", I mean: I would like to
don't care of how the strucs are saved on the file, I want to just
save/load my list, is it possible using the std?
On Dec 17, 4:59 am, major <oce...@despammed.comwrote:
Hi all,
I would like to store (and read) a list of structs into a file using c+
+ (each struct contains integers and strings), and I'm wondering if it
there is a method to do it at "high level", I mean: I would like to
don't care of how the strucs are saved on the file, I want to just
save/load my list, is it possible using the std?
It is possible with some implementations of the STL. The problem is
determining if your implementation can do it. It requires that the STL
containers actually use the pointer definition found in the allocator
parameter. So there is no portable way to do this, because the
standard doesnt require that an implementation actually use that
pointer definition. But a few do.
See the "Shared Memory container" example (pg 30) in this paper.
http://www.open-std.org/jtc1/sc22/wg...2007/n2486.pdf This
container also has the property that it can be read and written from a
file.
Lance
Dec 17 '07 #3
Michael DOUBEZ wrote:
major a écrit :
>Hi all,
I would like to store (and read) a list of structs into a file using
c+ + (each struct contains integers and strings), and I'm wondering
if it there is a method to do it at "high level", I mean: I would
like to don't care of how the strucs are saved on the file, I want
to just save/load my list, is it possible using the std?

There is no such thing in standard but there are many libraries out
there to do it.

See FAQ about serialization:
http://www.parashift.com/c++-faq-lit...alization.html

Michael
That is one thing I'd like C++ to have a type of for each for each variable
member of a class/structure. There are a few cases it would come in handy,
this being one of them. Another use would be tying a structure/class to a
database where I had to code each variable in the class.

You know, the constructor and detructor seem to have to be able to do this,
but I think that's on the compiler level, not C++ level.
--
Jim Langston
ta*******@rocketmail.com
Dec 17 '07 #4
On Dec 17, 10:59 am, major <oce...@despammed.comwrote:
I would like to store (and read) a list of structs into a file
using c+ + (each struct contains integers and strings), and
I'm wondering if it there is a method to do it at "high
level", I mean: I would like to don't care of how the strucs
are saved on the file, I want to just save/load my list, is it
possible using the std?
There's nothing standard. C++ doesn't define the representation
of anything, internally or externally. Internally, it typically
doesn't matter, but externally, you have to do it yourself (or
adopt some existing representation, like XDR). You can't even
really write an int, and expect to reread it reliably, without
defining its (or the file's) format. (Even in text a text, you
have to define things like separators.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Dec 18 '07 #5
On Dec 17, 8:59 pm, major <oce...@despammed.comwrote:
I would like to store (and read) a list of structs into a file using c+
[..]
save/load my list, is it possible using the std?
hi everybody,
thanks for your answer, I realised that saving a struct at "high
level" is not trivial, so I figured out a solution to do it in a
"lower level", not really elegant (or at least not as elegant as I
wanted) but it's fine.

cheers,
Mauro
Dec 20 '07 #6

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

Similar topics

1
by: Kay | last post by:
A linked list is storing several names. I want to make a queue if I input a name that is same as the linked list. How to make each node of a linked list storing a queue that are different with each...
2
by: Kay | last post by:
A linked list is storing several names. I want to make a queue if I input a name that is same as the linked list. How to make each node of a linked list storing a queue that are different with each...
14
by: Stainless | last post by:
I have a public class Globals, which obviously holds all my global data. I have an array of 243 items, currently structs of type typedef struct STAR { int x; int y; int stellar_class;...
5
by: Little | last post by:
I have this program and I need to work on the test portion, which tests if a Val is in the list. It returns false no matter what could you look at the part and see what might need to be done to fix...
3
by: prasanthag | last post by:
Hi, I am a newbie to this group. I have a problem in handling the variable arguments passed to a function. My requirement is like this. I have 2 functions say, void funcX(int i, int j);...
1
by: Miesha.James | last post by:
Hello, I'm trying to rewrite visual c++ code into visual c++ .NET code and I've run across a problem with storing objects into a list. Here;s an example of the code I have: ref struct...
0
by: NatsoumiMaya | last post by:
hi ppl, i have a code to write in C where i have to implement the mkdir, rm, rmdir and touch functions using double linked lists...im haveing trouble with it...here is what i have so far: #ifndef...
0
by: Atos | last post by:
SINGLE-LINKED LIST Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be...
7
by: pereges | last post by:
I've to store an array of structures: typedef struct { double origin; double e_field_at_origin_real, e_field_at_origin_imag; double direction; double pathlength; int depth; }ray;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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...
1
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.