Reputation: 11
I need to read a file as a binary code with Qt tools. In std c++ I did it like that:
#include <iostream>
#include <vector>
#include <fstream>
int main() {
std::ifstream file("C:\\Users\\%username%\\Desktop\\programme.exe",
std::ios::binary);
std::vector<char> vec((std::istreambuf_iterator<char>(file)),
(std::istreambuf_iterator<char>())); // that variable has the binary code
file.close();
return 0;
}
Upvotes: 1
Views: 168
Reputation: 4076
Qt is written using standard c++ as well as using native calls depending on OS and architecture. Therefore normal c++file I/O still works and is portable, otherwise have a look at the QFile documentation here. You would want to have a look at the examples that mention QDataStream
Upvotes: 2