c++ string char* const char*

#include <iostream>
#include <string>
#include <cstring>
using namespace std; int main()
{
{
string s = "tom and jerry";
const char* c_s = s.c_str();
cout << "---------------" << endl;
cout << c_s << endl;
cout << s << endl;
} {
const char* c_s = "tom and jerry";
string s(c_s);
cout << "---------------" << endl;
cout << c_s << endl;
cout << s << endl;
} {
string s = "tom and jerry";
char* c;
const int len = s.length();
c = new char[len+];
strcpy(c, s.c_str()); //#include <cstring>
cout << "---------------" << endl;
cout << c << endl;
cout << s << endl;
} {
char* c = "tom and jerry";
string s(c);
cout << "---------------" << endl;
cout << c << endl;
cout << s << endl;
} {
const char* c = "tom and jerry";
char* pc = new char[];
strcpy(pc, c);
cout << "---------------" << endl;
cout << c << endl;
cout << pc << endl;
} return ;
}
上一篇:嵌入式学习入门(一)-----基于 MDK 创建 STM32 汇编语言工程并分析 HEX 文件内容


下一篇:Shiro+JWT+Spring Boot Restful简易教程