📄 stringtest.cpp
字号:
#include <string.h>
#include <iostream.h>
#include <stdlib.h>
#include "String2.h" //包含顺序串类
void main(void)
{
String str1("Data Structrure"), str2("Learning "); //用构造函数1
String str3; //用构造函数1,取默认值
String str4(20); //用构造函数2
String str5(str1); //用拷贝构造函数
char st[] = "Data Structrure";
cout << "拷贝构造函数测试:" << endl << str5;
str2.Insert(9, st);
cout << "插入测试:" << endl << str2;
str2.Delete(0, 9);
cout << "删除测试:" << endl << str2;
str3 = str1.SubStr(5, 9);
cout << "取子串和对象赋值测试:" << endl << str3;
str4 = st;
cout << "字符串赋值测试:" << endl << str4;
cout << "输入流重载测试:" << endl;
cin >> str3;
cout << str3;
cout << "逻辑等于测试1:";
if(str1 == str5)cout << "String == String" << endl;
String str6("Structure");
cout << "逻辑等于测试2:";
if(str6 == "Structure") cout << "String == C++ string" << endl;
cout << "逻辑等于测试3:";
if("Structure" == str6) cout << "C++ string == String" << endl;
int t = Compare(str1, str1);
if(t == 0) cout << "string == String" << endl;
else cout << "string >< String" << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -