zoukankan      html  css  js  c++  java
  • const_cast

    #include <string>
    #include <iostream>
    using namespace std;
    
    void changeFirst(char* c)
    {
        c[0]+=1;
    }
    
    int main(int argc, char ** argv_)   
    {  
     int i = 100;  
     int *j = &i;  
     const int *k = const_cast<const int*>(j);  
     //const int *m = j;   感觉和这样写差不多  
      
     //指的地址都一样  
     cout <<i<<","<<&i<<endl; //100, 0012FF78  
     cout <<*j<<","<<j<<endl; //100, 0012FF78  
     cout <<*k<<","<<k<<endl; //100, 0012FF78  
      
    // *j = 200;  
    // *k = 200;   //error  
     string str("Hello");
     changeFirst(const_cast<char*>(str.c_str()));
     cout<<str.c_str()<<endl;
    
     return 0;  
    }  
    /*
    100,0012FF38
    100,0012FF38
    100,0012FF38
    Iello
    Press any key to continue
    */
  • 相关阅读:
    JQ 放大镜
    Jquery.tmpl
    Jquery Live方法
    Bootstrap之底层媒体查询
    Bootstrap 字体与图标
    工具提示
    模态框
    BootStrap格栅系统
    Tab选项卡
    弹出框
  • 原文地址:https://www.cnblogs.com/sky20080101/p/6405996.html
Copyright © 2011-2022 走看看