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

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

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

Boost には、hex()/unhex() などの関数がある。

wikipedia: Boost C++ライブラリ

boost hex

下記を参考にした。

Faith and Brave - C++で遊ぼう

int main()
{
    std::string s = "abc";
    std::string out;
    boost::algorithm::hex(s, std::back_inserter(out));
    std::cout << out << std::endl;
}

1行で記述できる。
このコードでは、std::string だが、 std::vector でもよい。

std::vector<char> bin
std::vector<char> hex;
boost::algorithm::hex(bin, std::back_inserter(hex));

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