#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语言代码)浏览:832 |
蛇行矩阵 (C语言代码)浏览:599 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:558 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:672 |
简单的a+b (C语言代码)浏览:681 |
C语言训练-8除不尽的数 (C语言代码)浏览:1460 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:491 |
求圆的面积 (C++代码)浮点数有误差!!!浏览:720 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:521 |
WU-IP判断 (C++代码)(一种有趣的实现方法)浏览:1561 |