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


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

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


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

示例1: main

int main() {
	const MyString cs("Ein konstanter String"); MyString s(cs);
	s.assign(cs);
	s.append(cs);
	cout << cs.c_str() << endl;
	cout << cs.size() << endl;
	cout << cs.capacity() << endl;
	cout << boolalpha << cs.empty() << endl;
	s = cs + cs;
	cout << (cs == cs) << endl;
	s = cs;
	cout << cs << endl;
	s.at(1) = 'X';
	s[2] = 'Y'; // Hallo
	cout << s << endl;
	cin.get();
return 0;
}
开发者ID:HSE-SWB2-OOS,项目名称:OOS-LB3,代码行数:18,代码来源:main.cpp

示例2: main

int main()
   {
   cout << "Testing default constructor\n\n";

   const MyString s1;
   
   cout << "s1: " << s1 << endl;   
   cout << "s1 size: " << s1.size() << endl;
   cout << "s1 capacity: " << s1.capacity() << endl;
   cout << "s1 is " << ((s1.empty()) ? "empty\n" : "not empty\n");
   cout << endl;
   
   cout << "Testing second constructor\n\n";
   
   MyString s2 = "some text";
   
   cout << "s2: " << s2 << endl;   
   cout << "s2 size: " << s2.size() << endl;
   cout << "s2 capacity: " << s2.capacity() << endl;
   cout << "s2 is " << ((s2.empty()) ? "empty\n" : "not empty\n");
   cout << endl;

   
   cout << "Testing second constructor with long string\n\n";
   
   MyString s3 = "This is a really long string and this time all of it will actually end up in the array - pretty neat, huh?";
   
   cout << "s3: " << s3 << endl;   
   cout << "s3 size: " << s3.size() << endl;
   cout << "s3 capacity: " << s3.capacity() << endl;
   cout << endl;


   cout << "Testing write form of subscript operator\n\n";
   
   s2[0] = 'S';
   s2[5] = 'T';
   cout << "s2: " << s2 << endl << endl;
      

   cout << "Testing read form of subscript operator\n\n";
   
   cout << "s2: ";
   for (unsigned int i = 0; i < s2.size(); i++)
      cout << s2[i];
   cout << endl << endl;

   cout << "Testing equality operators\n\n";

   const MyString s4 = "Some Text";
   
   cout << "s2 and s4 are " << ((s2 == s4) ? "equal\n" : "not equal\n");
   cout << "s3 and s4 are " << ((s3 == s4) ? "equal\n" : "not equal\n\n");
   
   cout << "s4 and \"Some Text\" are " << ((s4 == "Some Text") ? "equal\n" : "not equal\n");
   cout << "s4 and \"More Text\" are " << ((s4 == "More Text") ? "equal\n" : "not equal\n\n");
   
   cout << "\"Some Text\" and s4 are " << (("Some Text" == s4) ? "equal\n" : "not equal\n");
   cout << "\"More Text\" and s4 are " << (("More Text" == s4) ? "equal\n" : "not equal\n\n");

   cout << "Testing clear() method\n\n";

   s3.clear();
   
   cout << "s3: " << s3 << endl;   
   cout << "s3 size: " << s3.size() << endl;
   cout << "s3 capacity: " << s3.capacity() << endl;
   cout << "s3 is " << ((s3.empty()) ? "empty\n" : "not empty\n");

   cout << "Testing copy constructor\n\n";
   
   MyString s5(s4); // Problem
   
   cout << "s5: " << s5 << endl;   
   cout << "s5 size: " << s5.size() << endl;
   cout << "s5 capacity: " << s5.capacity() << endl;
   cout << endl;

   cout << "Testing assignment operator\n\n";
   

   s3 = s5;

   cout << "s3: " << s3 << endl;   
   cout << "s3 size: " << s3.size() << endl;
   cout << "s3 capacity: " << s3.capacity() << endl;
   cout << endl;

   s3 = "a different string";

   cout << "s3: " << s3 << endl;   
   cout << "s3 size: " << s3.size() << endl;
   cout << "s3 capacity: " << s3.capacity() << endl;
   cout << endl;

   cout << "Testing self-assignment\n\n";

   s3 = s3;

   cout << "s3: " << s3 << endl;   
//.........这里部分代码省略.........
开发者ID:BISmb,项目名称:CourseWork,代码行数:101,代码来源:driver.cpp


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