#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++代码)浏览:957 |
P1000 (C语言代码)浏览:881 |
图形输出 (C语言代码)浏览:1393 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:531 |
前10名 (C语言代码)浏览:744 |
复数求和 (C语言代码)浏览:933 |
A+B for Input-Output Practice (I) (C语言代码)浏览:575 |
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:1008 |
老王赛马 (C++代码)浏览:913 |
C二级辅导-阶乘数列 (C语言代码)浏览:1799 |