博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C与C++中string的区别与联系
阅读量:4223 次
发布时间:2019-05-26

本文共 683 字,大约阅读时间需要 2 分钟。

The good things about the two different strings types is that they are interoperable; you can copy from C to C++ or back again. C strings can be assigned to C++ strings directly and C++ strings have a function c_str() that returns the C string equivalent. This example shows a C string that is copied to a C++ string, printed out with cout then copied back into another C string and printed out using printf.

    

 for example

#include <iostream>
#include <string>

int main(int argc, char* argv[])
{


    char * name="My Name is David";
    std::string cppname=name;
    std::cout << cppname << std::endl;
    char cname[20];
    strcpy(cname,cppname.c_str());
    printf("Again, my name is %s",cname);
    return 0;

}

转载地址:http://pazqi.baihongyu.com/

你可能感兴趣的文章
有趣的Github项目万里挑一 !(附论文、项目链接)
查看>>
数据蒋堂 | Hadoop中理论与工程的错位
查看>>
收藏 | 精选11篇AI领域论文(附代码、数据集链接)
查看>>
2018全球大学AI排名:清华位列亚洲大学综合排名首位
查看>>
推导和实现:全面解析高斯过程中的函数最优化(附代码&公式)
查看>>
手把手教你上手python库pydbgen(附代码、安装地址)
查看>>
解析广泛应用于NLP的自注意力机制(附论文、源码)
查看>>
一文读懂深度学习模型近年来重要进展(附梳理图)
查看>>
ML:教你聚类并构建学习模型处理数据(附数据集)
查看>>
带你入门Python数据挖掘与机器学习(附代码、实例)
查看>>
资源 | UC Berkeley CS 294深度强化学习课程(附视频、学习资料)
查看>>
李飞飞团队最新论文:如何对图像中的实体精准“配对”?(附代码&论文)
查看>>
资源 | 25个深度学习开源数据集,have fun !
查看>>
数据蒋堂 | 存储和计算技术的选择
查看>>
白硕:区块链技术与数据隐私(附视频)
查看>>
手把手教你用Python进行回归(附代码、学习资料)
查看>>
9款超赞的AI开源项目!| 本周Github精选
查看>>
一文掌握机器学习必备数学知识(附学习资源)
查看>>
教你用R语言分析招聘数据,求职/转行不求人~(附代码、数据集)
查看>>
干货 | 20多门AI网络课程资源(附链接)
查看>>