techman999の日記

とある大学の教員の日々の備忘録

const unsigned char* をstring型へ変換

C++でconst unsigned char*型の文字列をstring型に変換するときのメモ

const unsigned char *tmp = "hoge";
string str = (reinterpret_cast(tmp));

C++でのキャストのメモ

  • static_cast

- 静的な普通の型変換

  • reinterpret_cast

- ポインタや参照の関係する強引な型変換
- reinterpret(再解釈する)、re-interpret

  • - const_cast

- ポインタや参照のconstを外す型変換