
This problem came about due to the fact I couldn't figure out how to implement (in your code) decode(in.end()). I really did try but concluded that I couldn't do with out losing the ablity to buid up my string translators by stepwise composition of inline code. This latter was important to me to guarentee optimal code generation so I wouldn't be tempted to make a bunch of translators for every combination. After much frustation I came to realized that it was easier to just avoid using (decode(in.end())). See test_iterators_base64 so use something like So your case might be altered to interate not on the input characters but rather on the output
typedef transform_width<binary_from_base64<std::(w?)string::const_iterator>,32,6> decode;
std::wostringstream out;
std::ostream_iterator<wchar_t,wchar_t> oit(out); decode iit(s); bits_size = in.size (32 / 6 ) // ? while(bit_size-- > 0){ *(oit++) = decode(*iit); Other misc observations: a) i notices you're using a 32 bit wchar_t - note that this is non-portable. I would think about using std::vector<boost::int_least32>. or maybe instead of using the "magic" number 32 you might want to try something like (sizeof(wchar_t) * 8). b) I'm not sure I remember where I handled the padding. you should double check that your if your original binary string isn't modulo 6 bits you might find it filled with 0 after a round trip through base64. Robert Ramey Stefan Strasser wrote:
Hi,
I need to write a std::wstring which can contain binary data like \0 to a xml attribute, so I'm converting it to base64 but I have problems decoding it: std::copy(decode(in.begin()),decode(in.end()),);
is this a correct way to decode base64? it works, but only if (bits % 6 == 0). otherwise the program is abort()ed due to an exception.
the string was encoded by base64_from_binary<transform_width<std::wstring::const_iterator,6,32>
Thanks,