Chunekit Pong wrote:
> On Thu, 20 Nov 2008 10:13:34 +0100, anon <> wrote:
>
>> Chunekit Pong wrote:
>>> What's the problem with this code?
>>>
>> It doesn't compile
>>
>>> the purpose is to convert binary file into a Base64 string
>>>
>> What's Base64 string?
>>
>>> I seem to have problem in the following line
>>> BYTE const* pbBinary = &bytes[0];
>>> int size = sizeof(pbBinary);
>>>
>> Most likely you will get 4 (depends on the platform you use)
>>
>>> =================
>>> typedef unsigned char BYTE;
>>> std::ifstream file1("c:/test2.png");
>>>
>>> // read from test2.png into BYTE array
>>> std::vector<BYTE> bytes(
>>> (std::istreambuf_iterator<char>(file1))
>>> , (std::istreambuf_iterator<char>())
>>> );
>> Is this working?
>>
>>> if(bytes.empty())
>>> ; // no bytes have been read
>>>
>>> BYTE const* pbBinary = &bytes[0];
>>> int size = sizeof(pbBinary);
>>>
>> I would do this:
>> const int size = bytes.size();
>
> the full C++ file is like this - should compile
> http://www.oniva.com/upload/1356/c3.cpp
To open a file for binary read, you need to create ifstream object like
this:
std::ifstream file1( "c:/test2.png",
std::ios_base::binary |
std::ios_base::in );
Are you sure CryptBinaryToString works fine?