C++中char* const char* string 之間的轉換複習

linukey發表於2015-04-26
//C++中char* const char* string 之間的轉換複習
#include<iostream>
#include<string.h>


using namespace std;
int main()
{
//string 轉 const char*
string str = "linukey";
const char* s = str.c_str();


//const char* 轉 string
const char* pstr = "linukey";
string ps(pstr);


//string 轉 char*
string pp = "linukey";
char* p = new char[pp.length() + 1];
strcpy(p, pp.c_str());


//char* 轉 string
char* ts = "linukey";
string tss(ts);


//const char* 轉 char*
const char* l = "linukey";
char* ll = (char*)l;







cin.get();
return 0;
}

相關文章