本文整理汇总了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;
}