UTF-8環境。
コードポイントというかバイト列をぐるぐるして中の値を表示しただけ。

サンプルコード。


#include <iostream>
#include <string>
#include <vector>
 
int main(int argc, char *argv[]){
 
  std::vector<std::string> slist;
  slist.push_back("hello");
  slist.push_back("あいうえお");
  slist.push_back(" ");
  slist.push_back(" ");
  slist.push_back("・");
  slist.push_back("A\r\nZ");
 
  for(std::vector<std::string>::iterator it = slist.begin(); it != slist.end(); it++){
    std::string s = *it;
    std::cout << "[" << s << "]" <<std::endl;
    const char* c = s.c_str();
    while(*c != '\0'){
      std::cout << (int)(char)*c << std::endl;
      c++;
    }
  }
}

実行結果。


$ g++ ./ccc.cpp
$ ./a.out 
[hello]
104
101
108
108
111
[あいうえお]
-29
-127
-126
-29
-127
-124
-29
-127
-122
-29
-127
-120
-29
-127
-118
[ ]
-29
-128
-128
[ ]
32
[・]
-29
-125
-69
[A
Z]
65
13
10
90

charとかwcharとかそういうちがいはよくわかっていない。

ちなみに環境。


$ uname -mrsv
Darwin 10.7.0 Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386 i386
 
$ g++ --version
i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Ref. 符号点 - Wikipedia

tags: c++ charset

Posted by NI-Lab. (@nilab)