1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#include <iostream> #include <iomanip> const int first = 0x21; const int last = 0x7e; const int height = 16; const int begin = (first / height * height); const int end = (last / height * height + height); const int width = (end - begin) / height; int main() { std::cout << std::hex << ' '; for(int i = begin; i < end; i += height) std::cout << std::setw(3) << "0x" << i; std::cout << std::endl; for(int i = 0; i < height; ++i) { std::cout << i; for(int j = 0; j < width; ++j) { int c = begin + i + j * height; std::cout << std::setw(5) << ((first <= c && c <= last) ? static_cast<char>(c) : ' '); } std::cout << std::endl; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
0x20 0x30 0x40 0x50 0x60 0x70 0 0 @ P ` p 1 ! 1 A Q a q 2 " 2 B R b r 3 # 3 C S c s 4 $ 4 D T d t 5 % 5 E U e u 6 & 6 F V f v 7 ' 7 G W g w 8 ( 8 H X h x 9 ) 9 I Y i y a * : J Z j z b + ; K [ k { c , < L \ l | d - = M ] m } e . > N ^ n ~ f / ? O _ o