I am trying to read the first 3 bytes of a file.
I am using Unicode.
My GCC 5.1 compiler is set to UTF-8.
In part of my attempts to read the bytes one at a time from the file (I can read the file already and get it's text), I have encountered the following error which I have not found sufficient documentation on to sufficiently understand it and work with it:
const std::string SomeFile = "xyz.txt";
std::ifstream SomeStreamOfTheFile(SomeFile, std::ios_base::binary);
std::vector<char> SomeVectorBuffer = ( std::istreambuf_iterator<char>(SomeStreamOfTheFile), std::istreambuf_iterator<char>() );
I get the following:
error: conversion from 'std::istreambuf_iterator<char, std::char_traits<char=""> >' to non-scalar type 'std::vector<char>' requested
I have been studying this but I do not yet know what it means.
Please help (with detailed explainations of your use of the std::istreambuf_iterator) in your help.
Thank you.
What I have tried:
Researching std::istreambuf_iterator and still not understanding how to fix this error.
I know that Template class istreambuf_iterator provides input iterator semantics for streambufs. But how to fix the current error?
I am using char because it is a Basic character set (size of 1 byte) and one byte at a time is what I want to read, from the file directly one byte at a time.
And, I can't do this:
char <char, std::char_traits<char=""> > SomeVectorBuffer = ( std::istreambuf_iterator<char>(SomeStreamOfTheFile) );
because char is not a template.
So, if I try this:
std::basic_string<char,char_traits<char>> SomeBuffer = ( std::istreambuf_iterator<char>(SomeStreamOfTheFile));
Even that does not work since I get the error:
conversion from 'std::istreambuf_iterator<char, std::char_traits<char=""> >' to non-scalar type 'std::__cxx11::basic_string<char>' requested
Some detailed help please.
Thank you.