#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 人评分
点我有惊喜!你懂得!浏览:1427 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:633 |
C二级辅导-公约公倍 (C语言代码)浏览:1541 |
C语言训练-素数问题 (C语言代码)浏览:1050 |
C语言程序设计教程(第三版)课后习题5.7 (Java代码)浏览:905 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:677 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:638 |
C二级辅导-进制转换 (C语言代码)浏览:743 |
矩形面积交 (C语言代码)浏览:1424 |
复数求和 (C语言代码)浏览:984 |