What is the difference between the << and Write streams

I opened the file in binary mode and wanted to write to the file.

   ofstream ofile("file.txt",ios_base::binary)
    int a = 1;
    float f = 0.1;
    string str = 10;
    ofile<<a<<f<<str;

Who knows what the difference is between using <<<and using "ofile.write". which is the best and most effective for binary recording.

+5
source share
2 answers

the <<operator will format your data as text. While the record will output data in the same format as in memory. So, if you are writing binary files, you want to use write.

However, if you write non-subtypes, you need to be careful. You cannot just say:

write( &mystring, sizeof(std::string) );

- , .

+5

AFAIK " ", , < < .

. , , .

, write, - ( , )

+1

All Articles