String is array of characters. Each character is on modern desktops is single 8-bit byte in size.
So string "Hello" in ASCII is sequence of bytes "48 65 6C 6C 6F 21 00" and will be written as such in binary file (which is too a sequence of byte)
Integers are several bytes in size (say 4 for Windows platform). So value of 4567784 will be saved as "00 45 B2 E8" or "E8 B2 45 00" depending on endianness of platform. When you will look in binary file, you will se series of 4 characters representing individual bytes: "E▓ш" or "ш▓E" (first — or last — symbol cannot be printed)
It depends what program you use in order to view the file contents. When i opened it in a text editor, it issued a warning that the file had not been completely loaded, and that the file might be damaged or not a plain text file.
The actual contents of the array is the same as if the code had been written like this:
In this case, the terminating null byte is actually written to the file, which you can see if you use a hex editor rather than an ordinary text editor to view the file.
Chervil... i tried to open with windows notepad and it's open it correctly with my string.
and what's the difference if i write it in string "My name is".. in this way terminating null added too, no?
char ch[] = "My name is"
ofstream fout("text.txt");
fout << ch;
then the terminating null character does not get written to the file, as it isn't considered a part of the string. But in the previous case, the null is written too.
I'd recommend a program such as hxd to view (or alter) the contents of binary files. It can show you content which text editors such as notepad cannot. http://mh-nexus.de/en/hxd/