進数の出力を含む文字列

免責事項:この記事はブロガーオリジナル記事ですが、許可ブロガーなく再生してはなりません。https://blog.csdn.net/liangzhao_jay/article/details/86703101

背景:漢字の文字列がUTF-8エンコーディングまたは他のエンコーディングので、この書き込み手順を含むかどうかを比較するための必要性

サンプルコード:

#include<iostream>
#include<string>
#include<sstream>
#include<iomanip>

using namespace std;

int main()
{
    string temp("ab中国");
    cout<<"源字符串    : "<<temp<<endl;
    stringstream out;
    for(string::const_iterator it != temp.begin(); it != temp.end(); ++it)
    {
        out<<std::hex<<setw(3)<<(static_cast<short>(*it) & 0xff);
    }
    cout<<"16进制字符串:"<<out.str();
    return 0;
}

 

おすすめ

転載: blog.csdn.net/liangzhao_jay/article/details/86703101