小垃圾的跟班


私信TA

用户名:1298743454

访问量:11494

签 名:

等  级
排  名 1832
经  验 2555
参赛次数 0
文章发表 23
年  龄 0
在职情况 学生
学  校 陕西科技大学
专  业

  自我简介:

  #include<iostream>
  #include<string.h>
  using namespace std;
  int main(int argc, char const *argv[]) {
    string one("pangchenbo");//对one进行初始化
    cout<<"one="<<one<<endl;
    string two(20,'$');//将$输出20遍
    cout<<"two="<<two<<endl;
    string three(one);//对one进行复制
    cout<<"three="<<three<<endl;
    one+="ops!";//在one的末尾添加字符
    cout<<"one="<<one<<endl;
    two="sorry! that was ";//对string变量two进行重新赋值
    three[0]='P';//赋值操作
    string four;
    four=two+three;//将两个变量加在第三变量上
    cout<<"four="<<four<<endl;
    char alls[]="ncjkdsnckjsdncjnkjs";
    string five(alls,20);//将一个char类型变量复制给string five
    cout<<"five="<<five<<endl;
    string six(alls+6,alls+10);//截取6-10之间的字符。指针
    cout<<"six="<<six<<endl;
    string seven(&five[6],&five[10]);//同上但不同方式。取地址。
    cout<<"seven="<<seven<<endl;
    string eight(four,7,16);//截取four中7-16的字符。
    cout<<"eight="<<eight<<endl;
    return 0;
  }

 

0.0分

0 人评分

  评论区