刨根问底系列之C++ 类型转换挖掘(二)

2014-11-24 03:30:38 · 作者: · 浏览: 1
里的memcpy函数。这种转换方式及其不安全,所以不推荐用。
const_cast 这种转换可以将常量转换为动态变量返回。
[cpp]
#include
#include
#include
using namespace std;
int main() {
const char* str = "hello,world";
try{
char* newStr = const_cast
(str);
cout<
for(int i =0; i
newStr[i] = 'x';
}
cout<
}catch(exception& e) {
cout<<"the exception is:"<
}
}