> I have a question, first time I use this. So ok I just started using
> FLTK

It seems you also started using C++.

> #include<string.h>

This is an old header file, you should use "#include <string>" without 
".h" to get the current STL library.

> struct TPerson { char name[255]; char vorname[255]; char email[255]; 
> }P;

Urgs!

struct TPerson
{
        string name;
        string vorname;
        string email;

        void read(istream& In)
        {
                std::getline(In, name, '\0');
                std::getline(In, vorname, '\0');
                std::getline(In, email, '\0');
        }

        void write(ostream& Out) const
        {
                Out << name << '\0';
                Out << vorname << '\0';
                Out << email<< '\0';
        }
};

Don't use char or char* if you can use string - you can be sure that 
sometimes on overflow or another error will appear - to me it is 
outdated style of programming.
If you are defining an object that is ment to be read or written, it 
should now how to read/write itself, so these functions should be part 
of the object. There are some other possibilities to read/write strings, 
the example uses zero terminated strings.

> strcpy(P.name,i->value());

Yes, this is exactly the way to write worst software - if you don't have 
a chance to avoid char[], you should use strncpy(), or limit the length 
of input. Using strings makes things more easy:

P.vorname= i->value();  // Reading Input

i->value(P.vorname.c_str());    // Preset Input

> ofstream datei("Personen.dat", ios::app);

That's not binary, but text mode:

ofstream datei("Personen.dat", ios::app | ios::binary);

> datei.write((char*)&P,sizeof(TPerson));

This writes the class including this-pointer, not only the data and will 
crash, when you read classes containing virtual functions. Using other 
kinds of data types you also can get problems with internal aligning - 
it is more save to write each variable in particular, as shown above:

P.write(datei);

> Can anybody help me with that please? Thanks in advance :D

de.comp.lang.iso-c++ should be helpful for you.

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to