Drkcore

27 04 2008 cpp Tweet

C++の配列の添え字

こんな感じでメモリに展開して、

int main() {
  string dit = "AB";
  bool SEL[256];
  memset( SEL, 0, sizeof(SEL));
  SEL[dit[0]] = 1;
  SEL[dit[1]] = 1;

  for(int i=0;i<sizeof(SEL);i++){
    cout << SEL[i];
  }
}

実行すると、

C:\msys\1.0\home\ohkw>test.exe
00000000000000000000000000000000000000000000000000000000000000000110000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000

きちんと対応する文字で1が立つ。でもSEL[char型のなんか] = 1;とやるとコンパイルエラーになるのがよくわからないなぁ。

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021