This can be best done using
printf
formatting:
FILE *f = fopen("test.txt", "w");
for (int i = 0; i < qba.size(); i++)
{
if (i)
fprintf(f, " ");
fprintf(f, "%02X", (unsigned char)qba.at(i));
}
fprintf(f, "\n");
fclose(f);
If your file is already opened by another method than
fopen
, check if you can get a
FILE
pointer for the opened file or use
sprintf
with a local buffer and write that to the file.
[UPDATE]
For an existing
QTextStream
like from the comment it can be:
mylog << " " << currtTimeStump "," << MsgDLC << "," << frameID << ",";
for (int i = 0; i < qba.size(); i++)
{
char dataByte[4];
sprintf(dataByte, " %02X", (unsigned char)qba.at(i));
mylog << dataByte;
}
mylog << '\n';