const char* to char*

C++ Syntax (Toggle Plain Text)
  1. char *FileExt = const_cast<char*> ( path.c_str() );
If you're not sure whether the function will modify the string or not, you haveno choice but to create a C-style string copy:
C++ Syntax (Toggle Plain Text)
  1. char *FileExt = new char[path.size() + 1];
  2. std::strcpy ( FileExt, path.c_str() );
strcpy is declared in <cstring>.

>oh and by the way ive tried casting it using static_cast
static_cast doesn't remove qualifiers, which is a very good thing because youhave to actively choose const_cast, and therefore can't do it by accident.
發佈了72 篇原創文章 · 獲贊 4 · 訪問量 24萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章