C++简单的基础类型转换

 直接上代码

#include 
#include 

using namespace std;

int zhlx(){
     //double(11) 将int类型 强转为double类型 
     //string转char*。主要有三种方法可将str转换为char*类型:data(); c_str(); copy();
     string str = "hello";//devc++中编译需要添加const,否则会报错invalid conversion from const char*  to char *
     const char* p = str.data();//加const  或者用char * p=(char*)str.data();的形式
    
     const char *p2 = str.c_str();//同上,要加const或者等号右边用char*   #include  //使用头文件string 
     cout<<"string转char*:"<< p <int:
     int int_temp=0;
     string string_temp="10";
     stringstream stream2(string_temp);  //应该是 通过第三方间接 进行转换   //#include   stringstream
     stream2>>int_temp;  
     cout <<"strint-->int:"<string:
     int sdfgv=22;
     string jis=""; 
     stringstream stream4;  
     stream4<string:"<

 

你可能感兴趣的:(C++,基础,c++,基础,转换)