(认知有限,如有不妥,还请告知,欢迎讨论)
#include
#include
#include
using std::string;
using std::cout;
using std::endl;
int main()
{
const char* sample_s = "sample pkc";
cout <<"The type of " << '"' << sample_s << '"' << " is " << typeid(sample_s).name() << "n"<< endl;
string sample_str = "sample str";
cout <<"The type of " << '"' << sample_str << '"' << " is " << typeid(sample_str).name() << "n"<< endl;
const char* s1 = "beginning pkc";
cout <<"The type of " << '"' << s1 << '"' << " is " << typeid(s1).name() << "n"<< endl;
//const char* 转 string
string str_1(s1);
cout <<"The type of " << '"' << str_1 << '"' << " now is " << typeid(str_1).name() << "n"<< endl;
string str_2 = "beginning string";
cout <<"The type of " << '"' << str_2 << '"' << " is " << typeid(str_2).name() << "n"<< endl;
// string 转 const char*
const char* s2=str_2.c_str();
cout <<"The type of " << '"' << s2 << '"' << " now is " << typeid(s2).name() << "n"<< endl;
return 0;
}
输出结果:
case CCommandLineInfo::FileNew:
if (!AfxGetApp()->OnCmdMsg(ID_FILE_NEW, 0, NULL, NULL))
OnFileNew();
if (m_pMainWnd == NULL)
bResult = FALSE;
break;
CFrameWnd* CDocTemplate::CreateNewFrame(CDocument* pDoc, CFrameWnd* pOther)
{
if (!pFrame->LoadFrame(m_nIDResource,……..)
return NULL;
}
The type of "sample pkc" is PKc
The type of "sample str" is NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
The type of "beginning pkc" is PKc
The type of "beginning pkc" now is NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
The type of "beginning string" is NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
The type of "beginning string" now is PKc
=END=



