0

I have a function which should output data from a file about a product which is typed in to the "keres variable. But when I am trying to compare the two strings it doesn't work.

    void Admin::display_one()
{
    string keres;
    Admin lidl;
    cout<<"Irja be a keresett termek nevet: ";
    getline(cin,keres);
    keres += "\r";
    ifstream file("termeklista.txt");
    file.read(reinterpret_cast <char*> (&lidl), sizeof(lidl));
    while(!file.eof())
    {
        if(lidl.nev == keres)
        {
         ....
        }
    file.read(reinterpret_cast <char*> (&lidl), sizeof(lidl));
     .....}

I wrote some post from here, I tried many form to put the additional "\r" in the end, but I think this is not the case at "serialized" ".txt" files. In the ".txt" file, I have:

       Hýb            tej            hýb            1$      ë     d       Hýb            kave           hýb            3$        

So could you help me in figuring out what's the solution Thank you for the accorded time.

  • Related : [Why is iostream::eof inside a loop condition (i.e. `while (!stream.eof())`) considered wrong?](https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-i-e-while-stream-eof-cons) – François Andrieux Apr 23 '21 at 14:50
  • "Serialized" and `read`ing entire binary objects is a contradiction. (Why do you have binary data in a ".txt" file?) – molbdnilo Apr 23 '21 at 15:00
  • I assume `nev` is a string member of the class Admin. Such an object can't be written to a file as a binary. – S.M. Apr 23 '21 at 15:08
  • Does this answer your question? [How to write std::string to file?](https://stackoverflow.com/questions/15388041/how-to-write-stdstring-to-file) – S.M. Apr 23 '21 at 15:10
  • I see. So I shouldn't use eof and I can't write strings to a file as binary. I am learning in an another language, so I am not pretty sure this operation has the name "serialization".So that's why I used quotes. So there is no way to do this comparison? – Szvitek96 Apr 23 '21 at 15:13

0 Answers0