I am working on a project that requires quick file input and output so I decided to use fread/fwrite. Fread works as intended but fwrite prints extra, random characters and I am not sure what the problem is.
for (int i = 0; i < vector.size(); ++i)
{
fwrite(&vector[i], vector.size(), sizeof(int), outfile);
fwrite("\n", 1, sizeof(char), outfile);
}
vector is of type int and in the first test case the output is expected to be from top-bottom:
3
2
1
The file does print it that way but it adds extra characters and thus it looks like so:
û° 3 ÌÌÌÌÌÌ
àý° 2 ÌÌÌÌÌÌ
xû° 1 ÌÌÌÌÌÌ
Any idea what might be wrong with the file output?