Problems casting a const char* to char*
来源:互联网 发布:开淘宝代购店怎么申请 编辑:程序博客网 时间:2024/05/16 10:57
char *FileExt = path.c_str();
I continually get the error message saying that it is not possible to convert const char * to char *!
解决方法:
The c_str() method of the std::string class returns a pointer to const char so that you can't modify the result. Unfortunately, there's no good solution, and you can thank the author of the library who didn't write const-correct code. Now, if you know that the function will not modify the string, you can use const_cast to allow the conversion:
1、C++ Syntax (Toggle Plain Text)
char *FileExt = const_cast ( path.c_str() );
If you're not sure whether the function will modify the string or not, you have no choice but to create a C-style string copy:
2、C++ Syntax (Toggle Plain Text)
char *FileExt = new char[path.size() + 1];
std::strcpy ( FileExt, path.c_str() );
- Problems casting a const char* to char*
- const char* to char*
- const char* const a
- cstring to char*,const char*
- cstring to char*,const char*
- cstring to char*,const char*
- cstring to char*,const char*
- jcharArray to const char[]
- const char *' to 'LPCWSTR'
- "QString" to "const char*"
- char ** a; const char ** b; char * const * c; const char * const * d; const char * const * const e;对
- invalid conversion from `const char*' to `char*'
- invalid conversion from 'const char*' to 'char*'
- invalid conversion from `const char*' to `char*' .
- invalid conversion from 'const char*' to char*
- invalid conversion from 'const char*' to 'char*'
- invalid conversion from `const char*' to `char*'
- char* a与char a[]的区别,const char* a与char* const a的区别
- 引用设置默认形参
- 还原ubuntu面板方法
- 展开树形控件atv第ai_s到ai_e层得节点,其他层得节点收起
- C++初学者指南 第十一篇(6)
- 关于build.xml文件编辑的个人整理
- Problems casting a const char* to char*
- 递归输出符合条件的组合
- HeadFirst 设计模式学习笔记22-- 备忘录(Memento)模式拾零
- 【转】java ant的详细介绍(被转的那位大牛原谅我,我也忘了从哪里找来的了)
- JDK自带的实用工具——native2ascii.exe
- 跪求一个protel 大一点的元器件库
- JavaScript 继承
- 10只魔戒——箴言
- C++读取以空格作为数据区分标记,以回车为行标记的txt文件到一个整数数组(字符串妙用)