I was wondering why the code below doesn't work. I'm trying to read a binary file byte by bite and convert it into text or numbers, preferably to numbers.
char readChar;
QFile infile
(Inname
);
if(!infile.
open(QIODevice::ReadOnly)) {exit(1);
}
while(!in_stream.atEnd())
{
in_stream >> readChar;
if(in_stream.atEnd()) {break;}
out_stream << readChar << "\n";
}
char readChar;
QFile infile(Inname); if(!infile.open(QIODevice::ReadOnly)) {exit(1);}
QTextStream in_stream(&infile);
QFile outfile(Outname); if(!outfile.open(QIODevice::WriteOnly | QIODevice::Text)) {exit(1);}
QTextStream out_stream(&outfile);
while(!in_stream.atEnd())
{
in_stream >> readChar;
if(in_stream.atEnd()) {break;}
out_stream << readChar << "\n";
}
To copy to clipboard, switch view to plain text mode
Then this should also allow reading binary file but how to convert it into int?:
qint64 bufSize = 1024;
char *buf = new char[bufSize];
qint64 dataSize;
while (!in_stream.atEnd())
{
dataSize = infile.read(buf, bufSize);
}
qint64 bufSize = 1024;
char *buf = new char[bufSize];
qint64 dataSize;
while (!in_stream.atEnd())
{
dataSize = infile.read(buf, bufSize);
}
To copy to clipboard, switch view to plain text mode
Bookmarks