首页 > 其他分享 >sting用法1

sting用法1

时间:2023-02-06 20:33:05浏览次数:31  
标签:pszConstString cout sting 用法 char String 张飞 string


# include <iostream>
# include <string>

using namespace std;

int main(){

char pszName[20] = "张飞";
char * pszName2 = "张飞";

string strName("张飞");
cout<<pszName<<endl;
cout<<pszName2<<endl;
cout<<strName<<endl;

string strName1 = "张飞";
cout<<strName<<endl;

//C字符串转换成C++
const char *pszConstString = "Hello String!";
string strFromConst(pszConstString); //复制
cout<<strFromConst<<endl;

//复制pszConstString的前5个
string strPartialCopy(pszConstString,5);
cout<<strPartialCopy<<endl;

//利用构造函数传递信息
string str2("Hello String");
string str2Copy(str2);//复制
cout<<str2Copy<<endl;


// 初始化10个a
string strRepeatChars(10,'a');
cout<< strRepeatChars<<endl;
return 0;
}


标签:pszConstString,cout,sting,用法,char,String,张飞,string
From: https://blog.51cto.com/u_15955675/6040459

相关文章

  • numpy的用法-02
    importnumpy#1.array把数组转化为矩阵In[9]:#itwillcomparethesecondvaluetoeachelementinthevector#Ifthevaluesareequal,thePythoninterpre......
  • numpy的用法-03
    #coding=utf-8importnumpyasnpimportnumpyaspia=np.arange(15).reshape(3,5)#arange����0-14������reshape���3*5�ľ���print(a)print(a.shape)#输出行和列的长度print(a.ndim)#t......
  • mysql concat函数的用法
    mysql中的这个函数非常强大,可以对查出的参数进行拼接,其实这个方法在java中也有api可以进行调用。那么什么时候进行使用呢?例如,你老大叫你做一个数据库的数据采集,需要整理成......
  • Javascript(es2016) import和require用法和区别
    写个简单js文件,假设名字为:lib.js。假设内容如下:exportconstsqrt=Math.sqrt;exportfunctionsquare(x){returnx*x;}exportfunctiond......
  • tf.split()函数的用法
    fromPILimportImageimportnumpyasnpimporttensorflowastf'''split对维度进行分割tf.split(data,数据图片(300*600*3)......
  • PostgreSQL数据库-Sequence的作用和用法
    PostgreSQL中的序列是一个数据库对象,本质上是一个自增器。所以,Sequence也可以通过在每个属性后加上autoincrment的值的形式存在。sequence的作用有两个方面:作为表的唯一......
  • Spring init-method与destroy-method属性的用法解析
    目录springinit-method与destroy-method属性使用知识点介绍:操作步骤:init-method="init"和destroy-method="close"作用 Springinit-method与destroy-method......
  • Python中and、or用法实例
    Python中and、or是Python中的逻辑运算符,它们的用法如何呢?and:在Python中,and和or执行布尔逻辑演算,如你所期待的一样,但是它们并不返回布尔值;而是,返回它们实际进行比较的值......
  • #ifndef #define,#endif 和 #if DEBUG,#endif的用法
    在一个大的软件工程里面,可能会有多个文件同时包含一个头文件,当这些文件编译链接成一个可执行文件时,就会出现大量重定义的错误。在头文件中实用#ifndef#define#endif能避免......
  • sqlmap工具的常用参数及用法
    介绍sqlmap是一个由python开发,开源的渗透测试工具,可以进行自动sql注入获取数据库信息,它同时支持windows和linux操作系统常用参数(sqlmap-u+“网址”+参数)1.-u可以......