I have this code:
int *size1 = new int();
int *size2 = new int();
QFile* file = new QFile("C:/Temp/tf.txt");
file->open(QFile::WriteOnly | QFile::Truncate);
file->write(str);
*size1 = file->size();
file->close();
file->open(QFile::WriteOnly | QFile::Truncate);
file->write(strC);
*size2 = file->size();
file->close();
delete file;
if (size1 < size2)
{
return true;
}
else
{
return false;
}
delete size1;
delete size2;
I want to compare bytes in file. But it comparing number of symbols in file.
Keep in mind that when you write a character to a file it’s probably going to be a byte, for the most part anyway.
Modified your code slightly. This then produces:
See how the file size matches the number of characters? Each character is a byte, that’s why it looks like it’s counted the characters.