J
Joy Maitland
how to use <iostream> to read a file to a const BYTE array?
const BYTE *pbBinary
const BYTE *pbBinary
how to use <iostream> to read a file to a const BYTE array?
const BYTE *pbBinary
how to use <iostream> to read a file to a const BYTE array?
const BYTE *pbBinary
You don't normally read a file into a pointer. You read a file into an
array and point that pointer to that array:
#include <iostream>
#include <vector>
#include <iterator>
int main()
{
typedef unsigned char BYTE;
// read from std::cin
std::vector<BYTE> bytes(
(std::istreambuf_iterator<char>(std::cin))
, (std::istreambuf_iterator<char>())
);
if(bytes.empty())
; // no bytes have been read
BYTE const* pbBinary = &bytes[0];
}
why when i change the code from std::cin to read from file
c:/test2.xml I got error
=======================
typedef unsigned char BYTE;
std:fstream file1("c:/test2.xml");
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.