YD Zhou
YD Zhou

Reputation: 327

Does c++ file ostream or file print function output '\0' to file when output a char array

I want to write some data to a binary file. I output a char array to a file like this

std::ofstream os;
os.open("myfile", std::ios::out | std::ios::binary);
os<<"A";
os.close();

or

char a[]="A";
File* file = fopen ("myfile","wb");
fprintf(file,"%s",a);

And in the end, does the file includes the '\0'?

In other words, the data of the file is 0x41 or 0x4100 in hexadecimal。

Upvotes: 0

Views: 85

Answers (1)

KamilCuk
KamilCuk

Reputation: 141493

And in the end, does the file includes the '\0'?

No. Strings are printed excluding terminating zero byte.

Upvotes: 1

Related Questions