本文介绍了使用stream将多个变量类型写入文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只想写一个简单的文本文件:
I just want to write a simple text file:
ofstream test;
test.clear();
test.open("test.txt",ios::out);
float var = 132.26;
BYTE var2[2];
var2[0] = 45;
var2[1] = 55;
test << var << (BYTE)var2[0] << (BYTE)var2[1];
test.close();
But in the output file I get:
132.26-7
问题是...
推荐答案
BYTE只是unsigned char的别名。默认情况下,在流中输出char时,将转换为其ASCII字符。在ASCII表中,字符45是 - ,字符55是7。
BYTE is nothing but an alias for unsigned char. By default, when you output a char in a stream, it is converted to its ASCII character. In the ASCII table, the character 45 is '-' and the character 55 is '7'.
请尝试:
test << var << (int)var2[0] << (int)var2[1];
这篇关于使用stream将多个变量类型写入文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!