📄 string.cpp
字号:
// string.cpp : Defines the entry point for the console application.
//
#include<iostream.h>
#include"SimpleString.h"
int main(int argc, char* argv[])
{
//测试构造函数
CSimpleString A("abc"),B("abcEF"), C(A), D(" ab ");
cout<<"String A="<<A<<"; "<<"String B="<<B<<"; "<<"String C="<<C<<"; "<<"String D="<<D<<";"<<endl;
cout<<endl;
//测试函数 IsEmpty()、TrimLeft()、TrimRight()、empty()
bool i=D.IsEmpty();
if(i==1) cout<<"String D is empty."<<endl;
if(i==0) cout<<"String D is not empty."<<endl;
cout<<"The length of string D is: "<<D.GetLength()<<endl;
D.TrimLeft();
cout<<"After delete the left space chars of D : D="<<D<<";"<<endl;
D.TrimRight();
cout<<"After delete the right space chars of D : D="<<D<<";"<<endl;
D.empty();
cout<<"After set D empty : The length of D is : "<<D.GetLength()<<" ";
i=D.IsEmpty();
if(i==1) cout<<"String D is empty."<<endl;
if(i==0) cout<<"String D is not empty."<<endl;
cout<<endl;
//测试函数 insert、delete 和 运算符 <、>、==
cout<<"Is A < B ? : "<< (A<B) <<endl;
cout<<"Is A > B ? : "<< (A>B) <<endl;
B.Insert(3,'d');
cout<<"After insert 'd' in B[3] : B="<<B<<endl;
B.Delete(0,4);
cout<<"After delete 4 chars begin at B[0] : B="<<B<<endl;
cout<<endl;
//测试运算符 +=、+
A+="d";
cout<<"The result of A+='d' is: A="<<A<<endl;
A+=B;
cout<<"The result of A+=B is: A="<<A<<endl;
C=A+"gh";
cout<<"The result of C=A+'gh' is: C="<<C<<endl;
cout<<endl;
//测试运算符 [] 和 强制类型转换运算符
A[3]='D';
cout<<"After A[3]='D' : A="<<A<<endl;
char ch=A[2];
cout<<"ch=A[2]="<<ch<<endl;
const char *p=(const char *)A;
cout<<"After *p=(const char *)A : (*p)="<<p<<endl;
cout<<endl;
//测试函数 MakeReverse()、MakeUpper()、MakeLower()
A.MakeReverse();
cout<<"After makereverse A="<<A<<endl;
A.MakeUpper();
cout<<"After makeupper A="<<A<<endl;
A.MakeLower();
cout<<"After makelower A="<<A<<endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -