c++ - Whats the difference between ofstream "<<" and Write -
i had opened file in binary mode , write file .
ofstream ofile("file.txt",ios_base::binary) int = 1; float f = 0.1; string str = 10; ofile<<a<<f<<str;
like know difference between writing using "<<" , using "ofile.write" . best , effective write in binary mode.
operator<< format data text. whereas write output data in same format it's stored in ram. so, if writing binary files, want use write.
however, if writing non-pod types, need careful. can't say:
write( &mystring, sizeof(std::string) );
you need have way output actual data, not stored in class or struct itself.
Comments
Post a Comment