![](/img/trans.png)
[英]How to read a file into unsigned char array from std::ifstream?
[英]How to read hex from a file and store it in an unsigned char?
文件包含字符“ 0”,“ x”,“ 5”,“ 1”和换行符。
QFile file ("config.txt");
QString fileContent;
if (file.open (QIODevice::ReadOnly))
{
QString line;
QTextStream t(&file);
do
{
line = t.readLine();
fileContent += line;
} while (!line.isNull());
file.close();
}
unsigned char m_pduAddress = fileContent.toUInt (0, 16);
如何从文件中读取十六进制并将其存储在未签名的char中?
我听说过的所有从十进制到十六进制的转换函数都使用char *。 我必须将结果存储在未签名的char中,而不是在char *中。
您可以直接从QTextStream
读取值:
QTextStream t(&file);
int value;
t >> value;
这将自动检测前导0x
,并将其余部分读取为十六进制数字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.