当前位置: 首页>>代码示例>>C++>>正文


C++ MyString::subString方法代码示例

本文整理汇总了C++中MyString::subString方法的典型用法代码示例。如果您正苦于以下问题:C++ MyString::subString方法的具体用法?C++ MyString::subString怎么用?C++ MyString::subString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MyString的用法示例。


在下文中一共展示了MyString::subString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main () {
	MyString A; // MyString object A is created and A contains the null string
	MyString B("Hello"); // MyString object B is created and B contains
	// the string "Hello"
	MyString C = " CS 115 class"; // MyString object C is created and C contains
	// the string " CS 115 class"
	MyString D(B); // MyString object D is created and D contains
	// the string "Hello"
	MyString E = C; // MyString object E is created and E contains
	//the string " CS 115 class"
	A = B; // resets the value of A to that of B
	cout << A << " " << B << endl; // outputs: Hello Hello
	A[0] = 'M';
	cout << A << " " << B << endl; // outputs: Mello Hello
	cout << "operator= and [] are working" << endl;
	D[0] = 'M';
	cout << D << " " << B << endl; // outputs: Mello Hello
	cout << "copy constructor is working" << endl;
	C = B + C;
	cout << C << endl; // outputs: Hello CS 115 class
	C = "MyString Class " + B + E;
	cout << C << endl; // outputs: MyString Class Hello CS 115 class
	if ( A < B )
		cout << "MyString has a bug in operator< function" << endl;
	else if ( A <= B )
		cout << "MyString has a bug in operator<= function" << endl;
	else if ( A == B )
		cout << "MyString has a bug in operator== function" << endl;
	else
		cout << "MyString comparison operators are working so far" << endl;
	if ( A != B && A > B && A >= B )
		cout << "All my comparison operators are working" << endl;

	MyString sub = C.subString(-1,2);
	cout<< "SubString of C is " << sub << endl;
	return 0;
}
开发者ID:shohoku11wrj,项目名称:algorithms,代码行数:37,代码来源:testMyArray.cpp


注:本文中的MyString::subString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。