//method 1
ofstream offile("DATA.txt");
offile<<"This is the first method\n";
1 2 3 4 5
//method 2
ofstream offile("DATA.txt");
char s[]="This is the first method\n";
offile.write(reinterpret_cast<char *>(s),25*sizeof(int));
offile.close();
What are the basic differences between the two methods and why can't we use string in method 2 there is still some 5 char junk value stored in the end of file in method 2 which i don't know how to remove though
No that doesn't help either
Instead of making a new thread i am going to write another question over here it does write but can't read what's wrong with this code
That code seems to work when I tried it. Of course there is no output on the screen in order to verify the result. How did you determine that it was not reading?
it doesn't show the expected data in edata.txt file
It's possible that the data was perfectly ok, but it just wasn't what you expected.
Note that in your code above, "edata.txt" is not a text file, because the file is opened in binary mode and the os.write() will output binary data to the file. Thus it cannot be read in an ordinary text editor.
What can i do to have the file readable for me are there any function for it and it should be .txt file or there isn't cause what if i need that data I don't understand honestly why would they do such a thing becuase later reading that data for a normal person is important and is it in binary form computer stores it in binary form
Those tools are perfectly fine for a programmer to work with binary files of any type. However, if you want the file contents to be readable by an ordinary person who has no need to delve into the inner workings of the data, then a binary file is the wrong choice. Either don't use binary mode at all in that case, or use binary for the program's own purposes, and create a separate report file to give to the ordinary person.
One small point, it's probably a good idea to give the file a different name, such as "edata.bin" of "edata.dat" for the binary file, and reserve the .txt extension for true text files.