2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

C++: base64 ライブラリの使い方

Last updated at Posted at 2021-08-14

こちらから、インクルードファイルをダウンロードします。
CLX C++ Libraries

解凍

tar xvfj clx_0.18.2.tar.bz2

プログラム

ex01.cpp
// -----------------------------------------------------------------------
/*
	ex01.cpp

						Aug/14/2021
*/
// -----------------------------------------------------------------------
# include <iostream>
# include <string>
# include <clx/base64.h>

// -----------------------------------------------------------------------
int main()
{
	std::cerr << "*** 開始 ***\n";

	std::string src = "ABCDEFG";

	std::string code = clx::base64::encode(src);

	std::cout << code << std::endl;

	std::cout << clx::base64::decode(code) << std::endl;

	std::cerr << "*** 終了 ***\n";

	return 0;
}

// -----------------------------------------------------------------------
Makefile
ex01: ex01.cpp
	clang++ -o ex01 ex01.cpp -I./
clean:
	rm -f ex01

コンパイル

make

実行結果

$ ./ex01 
*** 開始 ***
QUJDREVGRw==
ABCDEFG
*** 終了 ***

結果の検証

エンコード

$ echo 'ABCDEF' | base64
QUJDREVGCg==


デコード

>```text
$ echo 'QUJDREVGCg==' | base64 -d
ABCDEF

参考ページ
Base64 変換

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?