How do I use base64_from_binary from boost?

Hi Experts,

I tried adding a filter to some code, but I'm getting a compile error in Visual Studio 2008 with the following code - what do I do to get this going?  (error is "use of class template requires template argument list")

io::filtering_ostream out;
out.push(boost::archive::iterators::base64_from_binary());  // problem is here
std::string s = strFilename;
CString strText = "some text";
out << strText;

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It looks like you're not defining a type for one of your classes.  This is just a shot in the dark, but the compiler is probably looking for something along the lines of:

out.push(boost::archive<TypeOfArchive>::iterators::base64_from_binary());  // problem is here

Can you show where you initialize boost?
threadyAuthor Commented:
Thanks for the response - the code you see is all the code I used - I didn't do any other initialization.  What would I place in place of TypeOfArchive?  I'm a beginner with templates....
A little explanation of templates...

For example, the vector class manages an array of any data type you specify.  You can create a vector of ints, chars, etc...  They could have made a vector class for every single data type, but instead they just made a "template" for you to specify what type of vector you would like.  This is how you would declare a vector of ints.

vector<int> myIntVector;

And this is how you'd declare a vector of chars...

vector<char> myCharVector;

You get the picture...  Well, one of the classes within that erroneous line of yours needs a type specified for it.  That's what that error message means.  It would be like declaring:

vector myVector; //creates an error because no type was specified.

Hope this helps.
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

threadyAuthor Commented:
Hi Jonez,
Thanks for the explanation.  I still have no idea how to fix this for boost though.. I tried the following with no luck:

  -->  error C2882: 'archive' : illegal use of namespace identifier in expression

  --> error C2275: 'boost::archive::iterators::base64_from_binary<Base>' : illegal use of this type as an expression
1>        with
1>        [
1>            Base=char
1>        ]
Take a look at
#include "boost/archive/iterators/base64_from_binary.hpp"
#include "boost/archive/iterators/binary_from_base64.hpp"
#include "boost/archive/iterators/transform_width.hpp"
#include <string>
#include <iostream>
using namespace std;
using namespace boost::archive::iterators;
        transform_width<string::const_iterator, 6, 8>
        > base64_t;
        binary_from_base64<string::const_iterator>, 8, 6
        > binary_t;
int main()
    string str("Hello, world!");
    cout << str << endl;
    string enc(base64_t(str.begin()), base64_t(str.end()));
    cout << enc << endl;
    string dec(binary_t(enc.begin()), binary_t(enc.end()));
    cout << dec << endl;
    return 0;

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
threadyAuthor Commented:
Hi jkr,
Thanks for that - looks very nice - but I absolutely need to use the filter chain approach.  Maybe I'm wrong, but I don't think I can use these typedefs as a filter... (am I wrong? - really not sure)

io::filtering_ostream out;
out.push(boost::archive::iterators::base64_from_binary());  // problem is here

so when I write to out - it gets zipped - it gets base64 encoded - writes to file zipped and encoded...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.