运行以下代码:
ofstream newfile(path + "file" + ".hash", fstream::out);
filefl.open(path + "file" + ".hash", fstream::out);
char a = 10;
filefl<<a;
filefl.close();
生成一个包含 0D 0A
的文件(使用十六进制编辑器查看)。
当 a=9
包含 09
的文件时。
sizeof(char)
为 1。
我的操作系统是 win7 x64,代码是通过 vs2010 pro 运行的。
有人可以解释一下吗?
最佳答案
看起来流对象自动将换行符(0xA 或 10)扩展为 Windows 友好的回车换行符对 (0xD 0xA)。
关于c++ - 将数字写入文件 - 奇怪的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16574735/