c++打印ascii码表--wcout版

泪湿孤枕 提交于 2020-01-30 07:27:53
/*
 * C++ Program to Print ASCII table (0 - 127)
 */
 
#include<iostream>
#include<iomanip>
using namespace std;
 
wchar_t const* character[] = {L"NULL(空)", L"SOH(标题开始)", L"STX(正文开始)", L"ETX (正文结束)", L"EOT (传送结束)", 
                              L"ENQ (询问)", L"ACK (确认)", 
                            L"\\a",L"\\b",L"\\t",L"\\n",L"\\v",L"\\f",L"\\r",L"SO(移出)",L"SI(移入)", 
                              L"DLE(退出数据链)",
                            L"DC1 (设备控制1)", L"DC2(设备控制2)", L"DC3(设备控制3)", L"DC4(设备控制4)",
                              L"NAK (反确认)", L"SYN (同步空闲)", L"ETB (传输块结束)", L"CAN (取消)",
                            L"EM (媒介结束)", L"SUB (替换)", L"ESC (退出)", L"FS (文件分隔符)",
                              L"GS (组分隔符)", L"RS (记录分隔符)", L"US (单元分隔符)", L"(空格)"};
 
int main()
{
    locale::global(locale(""));
    wcout.imbue(locale(""));
    wchar_t c;
    int row;
    wcout << L" ASCII Table" << endl << L"=============" << endl;
    for(int i = 0; i < 32; i++)
    {
        row = i;
        while (row <= 127) {
            if (row <= 32){
                int len2=wcslen(character[row]);
                
                int width=15-(wcswidth(character[row],len2)-len2);
                wcout << setfill(L'0') << setw(2) << setbase(16)
                     << row << L" = " << setw(width) << setfill(L' ')
                     << character[row] << L" | ";
            }
            else if (row > 32 && row < 127)
            {
                c = (wchar_t)row;
                wcout << setfill(L'0') << setw(2) << setbase(16)
                     << row << L" = " << setw(15) << setfill(L' ')
                     << c << L" | ";
            }
            else
                wcout << setfill(L'0') << setw(2) << setbase(16)
                     << row << L" = " << setw(15) << setfill(L' ')
                     << L"DEL" << L" | ";
            row = row + 32;
        }
        wcout << endl;
    }
} 
 ASCII Table
=============
00 =        NULL(空) | 20 =          (空格) | 40 =               @ | 60 =               ` | 
01 =   SOH(标题开始) | 21 =               ! | 41 =               A | 61 =               a | 
02 =   STX(正文开始) | 22 =               " | 42 =               B | 62 =               b | 
03 =  ETX (正文结束) | 23 =               # | 43 =               C | 63 =               c | 
04 =  EOT (传送结束) | 24 =               $ | 44 =               D | 64 =               d | 
05 =      ENQ (询问) | 25 =               % | 45 =               E | 65 =               e | 
06 =      ACK (确认) | 26 =               & | 46 =               F | 66 =               f | 
07 =              \a | 27 =               ' | 47 =               G | 67 =               g | 
08 =              \b | 28 =               ( | 48 =               H | 68 =               h | 
09 =              \t | 29 =               ) | 49 =               I | 69 =               i | 
0a =              \n | 2a =               * | 4a =               J | 6a =               j | 
0b =              \v | 2b =               + | 4b =               K | 6b =               k | 
0c =              \f | 2c =               , | 4c =               L | 6c =               l | 
0d =              \r | 2d =               - | 4d =               M | 6d =               m | 
0e =        SO(移出) | 2e =               . | 4e =               N | 6e =               n | 
0f =        SI(移入) | 2f =               / | 4f =               O | 6f =               o | 
10 = DLE(退出数据链) | 30 =               0 | 50 =               P | 70 =               p | 
11 = DC1 (设备控制1) | 31 =               1 | 51 =               Q | 71 =               q | 
12 =  DC2(设备控制2) | 32 =               2 | 52 =               R | 72 =               r | 
13 =  DC3(设备控制3) | 33 =               3 | 53 =               S | 73 =               s | 
14 =  DC4(设备控制4) | 34 =               4 | 54 =               T | 74 =               t | 
15 =    NAK (反确认) | 35 =               5 | 55 =               U | 75 =               u | 
16 =  SYN (同步空闲) | 36 =               6 | 56 =               V | 76 =               v | 
17 = ETB (传输块结束) | 37 =               7 | 57 =               W | 77 =               w | 
18 =      CAN (取消) | 38 =               8 | 58 =               X | 78 =               x | 
19 =   EM (媒介结束) | 39 =               9 | 59 =               Y | 79 =               y | 
1a =      SUB (替换) | 3a =               : | 5a =               Z | 7a =               z | 
1b =      ESC (退出) | 3b =               ; | 5b =               [ | 7b =               { | 
1c = FS (文件分隔符) | 3c =               < | 5c =               \ | 7c =               | | 
1d =   GS (组分隔符) | 3d =               = | 5d =               ] | 7d =               } | 
1e = RS (记录分隔符) | 3e =               > | 5e =               ^ | 7e =               ~ | 
1f = US (单元分隔符) | 3f =               ? | 5f =               _ | 7f =             DEL | 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!