[C++] 24 文字列のバイト列への変換 文字化け調査

文字化けの原因調査等に必要なので記録しておきます。

#include <string>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <bitset>

using std::cout; using std::string;
using std::endl; using std::bitset;

void binary_convert(string str){
	for (int i = 0; i < str.length(); ++i) {
		bitset<8> bs4(str[i]);
		cout << str << " " << i+1 << "番目 " << bs4 << endl;
	}
	cout << "end"<< endl;
}

int main(int argc, char **argv){
	string str1 = "123";
	string str2 = "バイト列";

	binary_convert(str1);
	binary_convert(str2);
}
--------------------------------------------------

出力
--------------------------------------------------
123 1番目 00110001
123 2番目 00110010
123 3番目 00110011
end
バイト列 1番目 11100011
バイト列 2番目 10000011
バイト列 3番目 10010000
バイト列 4番目 11100011
バイト列 5番目 10000010
バイト列 6番目 10100100
バイト列 7番目 11100011
バイト列 8番目 10000011
バイト列 9番目 10001000
バイト列 10番目 11100101
バイト列 11番目 10001000
バイト列 12番目 10010111
end