#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 人评分
C二级辅导-等差数列 (C语言代码)浏览:1297 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:972 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:696 |
兰顿蚂蚁 (C++代码)浏览:1145 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:624 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:640 |
青年歌手大奖赛_评委会打分 (C语言代码)浏览:2230 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:740 |
逆反的01串 (C语言代码)浏览:1513 |
C二级辅导-阶乘数列 (C语言代码)浏览:669 |