Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #6234

Re: Persisting a structure: Valgrind errors

Newsgroups comp.lang.c++
Subject Re: Persisting a structure: Valgrind errors
References <ise7gc$6k2$1@dont-email.me>
Date 2011-06-05 12:04 +0200
From Asger-P <junk@asger-p.dk>
Organization Asger-P
Message-ID <op.vwlkxlty2juju3@ajwin7> (permalink)

Show all headers | View raw


Hi Ramon

On the: 04. of juni-2011 At: 23:19 Ramon wrote:

> Hello,
>
> Though I have a good amount of experience in ANSI C, Java, C#...etc, I  
> am fairly new with C++.

In C++ You need to think more in letting the object handle
its own data.


#include <iostream>
#include <fstream>
#include <string>

using namespace std;

struct record
{
    string name;
    string surname;

    void saveToStream( fstream &strm )
    {
       strm << name << endl;
       strm << surname << endl;
    }
    void readFromStream( fstream &strm )
    {
       getline( strm, name );
       getline( strm, surname );
    }
};


I dont use STL much, so I dont know if this is the best way,
but I'm sure You get the picture


Best regards
Asger-P

Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Persisting a structure:  Valgrind errors Ramon <ramif_47.invalid@yahoo.co.uk> - 2011-06-04 23:19 +0200
  Re: Persisting a structure:  Valgrind errors Ian Collins <ian-news@hotmail.com> - 2011-06-05 10:59 +1200
    Re: Persisting a structure: Valgrind errors Ebenezer <woodbrian77@gmail.com> - 2011-06-04 18:11 -0700
      Re: Persisting a structure: Valgrind errors Öö Tiib <ootiib@hot.ee> - 2011-06-04 18:56 -0700
  Re: Persisting a structure:  Valgrind errors Juha Nieminen <nospam@thanks.invalid> - 2011-06-05 05:57 +0000
    Re: Persisting a structure:  Valgrind errors "io_x" <a@b.c.invalid> - 2011-06-05 08:14 +0200
      Re: Persisting a structure:  Valgrind errors Ramon <ramif_47.invalid@yahoo.co.uk> - 2011-06-05 11:40 +0200
        Re: Persisting a structure:  Valgrind errors "io_x" <a@b.c.invalid> - 2011-06-05 12:17 +0200
          Re: Persisting a structure:  Valgrind errors Ramon <ramif_47.invalid@yahoo.co.uk> - 2011-06-05 18:15 +0200
            Re: Persisting a structure:  Valgrind errors Asger-P <junk@asger-p.dk> - 2011-06-05 18:44 +0200
            Re: Persisting a structure:  Valgrind errors Juha Nieminen <nospam@thanks.invalid> - 2011-06-07 06:20 +0000
              Re: Persisting a structure: Valgrind errors Joshua Maurice <joshuamaurice@gmail.com> - 2011-06-07 00:24 -0700
                Re: Persisting a structure: Valgrind errors Juha Nieminen <nospam@thanks.invalid> - 2011-06-07 08:40 +0000
                Re: Persisting a structure: Valgrind errors Miles Bader <miles@gnu.org> - 2011-06-08 14:43 +0900
                Re: Persisting a structure: Valgrind errors Joshua Maurice <joshuamaurice@gmail.com> - 2011-06-07 23:37 -0700
                Re: Persisting a structure: Valgrind errors Miles Bader <miles@gnu.org> - 2011-06-08 17:18 +0900
        Re: Persisting a structure:  Valgrind errors Nobody <nobody@nowhere.com> - 2011-06-05 18:42 +0100
    Re: Persisting a structure: Valgrind errors Ebenezer <woodbrian77@gmail.com> - 2011-06-05 13:22 -0700
  Re: Persisting a structure:  Valgrind errors Asger-P <junk@asger-p.dk> - 2011-06-05 12:04 +0200

csiph-web