This code is in Unit1.h

struct gydytojas {
   int gydid, amzius, specialyb, telefonas, asmkod;
   String vardas[25];
   String pavarde[35];
   String adresas[50];
  friend ostream& operator<<(ostream& os, const gydytojas& obj)
    {

     

          return os;
        };
  friend fstream& operator>>(fstream& os, const gydytojas& obj)
   {

 
      return os;
     };

  };    

gydytojas gydmas[100];

And this code is in Unit1.ccp

gydytojas pgyd;
pgyd.vardas[25]=Edit21->Text;
pgyd.pavarde[35]=Edit22->Text;
pgyd.adresas[50]=Edit24->Text;
pgyd.asmkod=StrToInt(Edit23->Text);
pgyd.amzius=StrToInt(Edit27->Text);
pgyd.gydid=StrToInt(Edit26->Text);
pgyd.telefonas=StrToInt(Edit25->Text);
pgyd.specialyb=ComboBox5->ItemIndex;
gydmas[1]=pgyd;
ofstream fr("Gydytojai.sed";)
 for (int i=1;i<2;i++){ fr << gydmas[i];};
fr.close();

The file Gydytojai.sed is created, but it is empty.

Perhaps because your functions are empty, so they do nothing.
Or perhaps because pgyd.vardas[25]=Edit21->Text; is an array overflow and everything has been trashed so it no longer works.

I sense some confusion between a char array and a std::string in your declarations. If you're only looking for ONE string, then either

char vardas[25];
....
strcpy( pgyd.vardas, Edit21->Text );

OR

string vardas;
....
pgyd.vardas = Edit21->Text;
struct gydytojas {
    <snip>

  friend ostream& operator<<(ostream& os, const gydytojas& obj)
  {
      // In this function you have to write the data you want
      // in to the ostream os.

      // for example, write the integer values
      os << obj.gydid
          << obj.amzius
          << obj.specialyb
          << obj.telefonas
          << obj.asmkod;

      // All written ... return the stream object
      return os;
  };

  // You cannot pass a const gydytojas obj here,
  //  since you intend to load data into it
  friend fstream& operator>>(fstream& os, /*const */ gydytojas& obj)
   {
       // Todo: load the data ...
 
      return os;
     };
  };

I suspect that Salem has it right pointing out the String array usage, i.e. given that vardas actually translates to 'first name' (does it?), you should/could change it to
string vardas;
or
String vardas;
And the other variables alike too.

struct gydytojas {
    <snip>

  friend ostream& operator<<(ostream& os, const gydytojas& obj)
  {
      // In this function you have to write the data you want
      // in to the ostream os.

      // for example, write the integer values
      os << obj.gydid
          << obj.amzius
          << obj.specialyb
          << obj.telefonas
          << obj.asmkod;

      // All written ... return the stream object
      return os;
  };

  // You cannot pass a const gydytojas obj here,
  //  since you intend to load data into it
  friend fstream& operator>>(fstream& os, /*const */ gydytojas& obj)
   {
       // Todo: load the data ...
 
      return os;
     };
  };

I suspect that Salem has it right pointing out the String array usage, i.e. given that vardas actually translates to 'first name' (does it?), you should/could change it to
string vardas;
or
String vardas;
And the other variables alike too.

Oh, thanks for explanation, i was abit confused what i should write in that function as i what I've tried, that was bad, anyway going to try now ;) Thanks both of you

Eh i get an error:
Unit1.h(209): decision to instantiate: ostream & operator <<(ostream &,const TForm1::gydytojas &)

Tried to google, and find answers, but most of them gves the information of GNU compiler connection..

It might help if you post the code and the complete error message BCB gives.

struct gydytojas {
   int gydid, amzius, specialyb, telefonas, asmkod;
   String vardas;
   String pavarde;
   String adresas;
  friend ostream& operator<<(ostream& os, const gydytojas& obj)
    {

         os << obj.vardas;
            << obj.pavarde;
            << obj.adresas;
            << obj.gydid;
            << obj.amzius;
            << obj.specialyb;
            << obj.telefonas;
            << obj.asmkod;

          return os;
        };

This is in Unit1.h

And the error is:
Unit1.h(209): parsing: ostream & operator <<(ostream &,const TForm1::gydytojas &)

Hmm .. there were some severe errors that need to be fixed first (didn't notice those at first, sorry), byt anyway ..

friend ostream& operator<<(ostream& os, const gydytojas& obj)
{
         os << obj.vardas.c_str()  // need to add call to c_str() 
            << obj.pavarde.c_str() // because ostream knows nothing
            << obj.adresas.c_str() // about AnsiString
            << obj.gydid
            << obj.amzius
            << obj.specialyb
            << obj.telefonas
            << obj.asmkod  ;  // <- semicolon needed only here 

          return os;
}/* ; <- semicolon should not be here because this function is defined inside the gydytojas class */

Well, ye about the ansi it is correct, but error still exists on same lines:

[C++ Error] Unit1.h(210): E2294 Structure required on left side of . or .*
Full parser context
Unit1.h(209): decision to instantiate: ostream & operator <<(ostream &,const TForm1::gydytojas &)
--- Resetting parser context for instantiation...
Unit1.h(209): parsing: ostream & operator <<(ostream &,const TForm1::gydytojas &)

Getting really confusing ...
given that line 210 contains "os << obj.vardas.c_str()" and actually produces the error message, does not make much sense, seems like the compiler would be completely unaware of the class itself. On the other hand, compiler errors can be quite misleading at times, so the initial reason may also be elsewhere.

Hmm .. you might as well try to see if specifying TForm1:: makes BCB happy (though I doubt it), i.e.

friend ostream& operator<<(ostream& os, const TForm1::gydytojas & obj)

It's abt confusing, the error is the same if i change const TForm1::gydytojas..

Gona look through google..Anyway if anyone has suggestion how it should be performed, just write.

friend ostream& operator<<(ostream& os, const TForm1::gydytojas& obj)
{
         os << obj.vardas.c_str()  
            << obj.pavarde.c_str() 
            << obj.adresas.c_str() 
            << obj.gydid
            << obj.amzius
            << obj.specialyb
            << obj.telefonas
            << obj.asmkod  ;  

          return os;

If you cannot get it figured out, then zip the complete BCB project and post it here.

If you cannot get it figured out, then zip the complete BCB project and post it here.

Okay, here is the link Press Here This is just the start of that project, and the main thing should be ofstream & istream + structures.

The reason why it did not compile is that you still have arrays of Strings (vardas, pavarde and adresas), although in the previous post it appeared otherwise - hence the compiler rightfully complained "Structure required on left side of . or .*", when doing e.g. os << vardas.c_str() To fix it just use plain String variables as shown below...

struct gydytojas 
{
   String vardas; // [25];
   String pavarde; // [35];
   String adresas; // [50];

Those 3 lines above are the only ones you need to change.

Aww, man thanks for help, i did that before, but borland went off, and i just missed to see it :S Anyway i'm very grateful for the help, just now will be interesting thing, as i saw how it writes to files, it is just a line, will it could be read and used in the exact order as name, surname, address..;) Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.