落書きノート

ふと自分が気になった事を書いてます

慣習 C++で問題を解く

今回はこんな感じです。環境の調査みたいな感じですね。

#include <climits>
#include <iostream>

using namespace std;

int main(void){
  
  cout << "この処理系での文字列の特性" << endl;
  cout << "ビット数:" << CHAR_BIT << endl;
  cout << "char:" << CHAR_MIN << "~" << CHAR_MAX << endl;
  cout << "signed char:" << SCHAR_MIN << "~" << SCHAR_MAX << endl;
  cout << "unsigned char:" << 0 << "~" << UCHAR_MAX << endl;
  cout << "char型は符号" << (CHAR_MIN ? "付き":"無し") << "型です。" << endl;

  return 0;
}

#include <iostream>

using namespace std;

int main(void){

  cout << "'0':" << dec << int('0') << ' ' << hex << int('0') << endl;
  cout << "'1':" << dec << int('1') << ' ' << hex << int('1') << endl;
  cout << "'2':" << dec << int('2') << ' ' << hex << int('2') << endl;
  cout << "'3':" << dec << int('3') << ' ' << hex << int('3') << endl;
  cout << "'4':" << dec << int('4') << ' ' << hex << int('4') << endl;
  cout << "'5':" << dec << int('5') << ' ' << hex << int('5') << endl;
  cout << "'6':" << dec << int('6') << ' ' << hex << int('6') << endl;
  cout << "'7':" << dec << int('7') << ' ' << hex << int('7') << endl;
  cout << "'8':" << dec << int('8') << ' ' << hex << int('8') << endl;
  cout << "'9':" << dec << int('9') << ' ' << hex << int('9') << endl;
  
  return 0;
}

#include <cctype>
#include <climits>
#include <iomanip>
#include <iostream>

using namespace std;

int main(void){

  cout << "この処理系の文字と文字コード" << endl;
  
  for(char i = 0;; i++){
    switch(i){
      case '\a': cout << "\\a"; break;
      case '\b': cout << "\\b"; break;
      case '\f': cout << "\\f"; break;
      case '\n': cout << "\\n"; break;
      case '\r': cout << "\\r"; break;
      case '\t': cout << "\\t"; break;
      case '\v': cout << "\\v"; break;
      default: cout << ' ' << (isprint(i) ? i : ' ');
    }

    cout << ' ' << hex << setw(2) << int(i) << ' ';

    if(isspace(i))
      cout << "空白類文字";
    else if(isdigit(i))
      cout << "10進数字";
    else if(islower(i))
      cout << "英小文字";
    else if(isupper(i))
      cout << "英大文字";
    else if(isgraph(i))
      cout << "記号文字";
    else if(iscntrl(i))
      cout << "制御文字";

    cout << endl;

    if(i == CHAR_MAX) break;
  }

  return 0;
}