• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4584
  • Last Modified:

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

  • 3
  • 2
1 Solution
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.
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

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 http://sakhnik.blogspot.com/2007/04/base64-transformations-in-c.html
#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

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...

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now