#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 ;
}

c++ string char* const char*的更多相关文章

  1. 【转】char*,const char*和string的相互转换

    1. string转const char* string s = "abc"; const char* c_s = s.c_str(); 2. const char*转string ...

  2. char*,const char*和string的相互转换

    好久没写东西啦,发表学术文章一篇,hiahia~ 近日和小佳子编程时遇到很多转换问题,很麻烦,在网上查了很多资料. 为了以后查找方便,特此总结如下. 如果有不对的地方或者有更简单的方法,请指出~~ 1 ...

  3. std::string stringf(const char* format, ...)

    std::string stringf(const char* format, ...){ va_list arg_list; va_start(arg_list, format); // SUSv2 ...

  4. string、const char*、 char* 、char[]相互转换

    转化总结如下: 目标格式 源格式 string const char* char* char[] string NULL const char*=string.c_str(); const char* ...

  5. CString、string、const char*的相互转换

    环境:vs2010 1.CString转string //第一种方式: CString str = _T("CSDN"); USES_CONVERSION; std::string ...

  6. (c++) int 转 string,char*,const char*和string的相互转换

    一.int 和string的相互转换 1 int 转化为 string c++ //char *itoa( int value, char *string,int radix); // 原型说明: / ...

  7. string、const char*、 char* 、char[]相互转换(待整理)

    string.const char*. char* .char[]相互转换(全) https://blog.csdn.net/rongrongyaofeiqi/article/details/5244 ...

  8. string char * const char *之间的互相转换

    string  ->   const char * 用str的c_str()方法或者data()方法均可,这个两个方法返回值为cong char * string str = "hel ...

  9. 转载:string、const char*、 char* 、char[]相互转换

    本文转自:https://blog.csdn.net/rongrongyaofeiqi/article/details/52442169 一:转化总结形式如下: 使用时,要对源格式和目标格式进行初始化 ...

  10. How to convert a std::string to const char* or char*?

    How to convert a std::string to const char* or char*? 1. If you just want to pass a std::string to a ...

随机推荐

  1. replace替换语句

    t_sql语句:replace替换语句:update 表名 set 列名=REPLACE(列名,'替换的数据','替换后的数据')

  2. SQLSERVER2012数据库还原

    (1)还原已存在数据库 还原时提示失败,因为数据库正在使用,无法获得独占访问权.解决办法,先分离已存在的数据库,再执行还原操作. 确定后居然成功了,因为我是先使用(2)还原数据库后直接尝试(1)方法还 ...

  3. .net chart(图表)控件的使用-System.Windows.Forms.DataVisualization.dll

    这个案例指在介绍微软这套免费又功能强大的图表控件Microsoft Chart Controls for Microsoft .NET Framework 3.5,通过它,可让您的项目及报表,轻松套用 ...

  4. 判断DataReader中是否有指定列

    取出的DataReader如果在读取过程中报没有列的错误可以用这个方法. //调用该方法判断datareader中是否有指定列 public static bool readerExists(IDat ...

  5. blazeds使用remote访问

     欢迎交流转载,请注明出处:http://www.cnblogs.com/shizhongtao/p/3487128.html 1.配置及说明 jar包说明 从官方上下的Blazeds中,默认的配置有 ...

  6. 洛古 P1373 小a和uim之大逃离

    P1373 小a和uim之大逃离 题目提供者lzn 标签 动态规划 洛谷原创 难度 提高+/省选- 题目背景 小a和uim来到雨林中探险.突然一阵北风吹来,一片乌云从北部天边急涌过来,还伴着一道道闪电 ...

  7. Atl笔记二:BEGIN_COM_MAP

    1,offsetofclass获取基类相对于子类的偏移位置. #define _ATL_PACKING 8#define offsetofclass(base, derived) ((DWORD_PT ...

  8. ClassLoader源码

    最近找工作,面试网易和微策略,都问到了ClassLoader这个东西,看来应该是比较重要的,所以在这总结一下,嗯,类源码有点长,慢慢看吧. 翻译一下,不当之处欢迎指正. /** * A class l ...

  9. input中id和name属性的区别。

    input中id和name属性的区别. 做网站很久了,但到现在还没有搞明白input中name和id的区别,最近学习jquery,又遇到这个问题,就在网上搜集资料.看到这篇,就整理出来,以备后用. 可 ...

  10. AngularJS(6)-选择框Select

    1.在 AngularJS 中我们可以使用 ng-option 指令来创建一个下拉列表,列表项通过对象和数组循环输出 <!DOCTYPE html> <html lang=" ...