C++ にて Boost を使ってバイナリデータを Base64 文字列に変換する

C言語にてバイナリデータを Base64 文字列に変換する
の続きです。

Boost はC++用のソフトウェアライブラリです。

Base64の変換テーブルを内蔵していて、base64_from_binary などの関数がある。

wikipedia: Boost C++ライブラリ

boost base64_from_binary.hpp

下記を参考した。

Boostライブラリでbase64へのコンバートとデコード

template <typename InputStream, typename OutputStream>
inline OutputStream& encode(InputStream& is, OutputStream& os) {
  copy(EncodeItr(InputItr(is)), EncodeItr(InputItr()), OutputItr(os));
  return os;
}

イテレータを使ってシンプルに記述できる。

Stream は扱いにくいので、APIを std::string std::vector に変更する。

std::string encode_base64( std::vector vec)

サンプルコードをguthubに公開した。 https://github.com/ohwada/MAC_cpp_Samples/tree/master/boost/base64