Hello! Here is part of the task (os - object ostream, s - object string)

Написать функтор Store, который записывает строковую информацию в файл. Конструктор Store должен указывать объект ifstream, а перегруженная функция operator () (const string &) должна указывать строку, подлежащую записи. Приемлемый подход состоит в записи в файл сначала размера строки, а затем — ее содержимого. Например, если len содержит размер строки, можно было бы использовать следующие операторы: os.write((char *)&len, sizeof(std::size_t)); // сохранить длину os.write(s.data(), len); // сохранить символы Член data () возвращает указатель на массив, который содержит символы строки. Он подобен члену c_str(), за исключением того, что последний добавляет нулевой символ. 

What are these two lines for?

  • > What are these two lines for? Obviously, to write to the file, first the length of the string, then the string itself. Here you are all explained by letter, what exactly is unclear from this? - user6550 pm
  • That is, the file will be written, for example, 4abcd, or 4 free characters will be allocated, which will be replaced by the word abcd? Simply put, why do we need the first line? - dbs1024 pm
  • The first line does exactly what it says: writes the value of the variable len to the file. - user6550
  • I conducted the test, compiled the program, and the first line writes several obscure characters to the file instead of the line length. - dbs1024 6:08 pm
  • one
    Unintelligible to you , because this is how the binary representation of a number is recorded, not the textual one (not to be confused with the textual representation of a number in the binary number system). In general, you would take textbooks and catch up on material that was missed ... - user6550

0