本文整理汇总了C++中String::Capacity方法的典型用法代码示例。如果您正苦于以下问题:C++ String::Capacity方法的具体用法?C++ String::Capacity怎么用?C++ String::Capacity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String::Capacity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EvaluateToString
String XPathQuery::EvaluateToString(XMLElement element) const
{
if (!query_ || ((!element.GetFile() || !element.GetNode()) && !element.GetXPathNode()))
return String::EMPTY;
const pugi::xml_node& node = element.GetXPathNode() ? element.GetXPathNode()->node(): pugi::xml_node(element.GetNode());
String result;
result.Reserve(query_->evaluate_string(0, 0, node)); // First call get the size
query_->evaluate_string(const_cast<pugi::char_t*>(result.CString()), result.Capacity(), node); // Second call get the actual string
return result;
}
示例2:
String::String(const String& c)
{
sizeMemory = c.Capacity();
strng = new char[sizeMemory];
strcpy_s(strng, sizeMemory, c.strng);
}
示例3: main
int main()
{
#ifdef _MSC_VER
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
printf("Size of String: %d\n", sizeof(String));
printf("Size of Vector: %d\n", sizeof(Vector<int>));
printf("Size of List: %d\n", sizeof(List<int>));
printf("Size of HashMap: %d\n", sizeof(HashMap<int, int>));
printf("Size of RefCounted: %d\n", sizeof(RefCounted));
{
printf("\nTesting AutoPtr assignment\n");
AutoPtr<Test> ptr1(new Test);
AutoPtr<Test> ptr2;
ptr2 = ptr1;
}
{
printf("\nTesting AutoPtr copy construction\n");
AutoPtr<Test> ptr1(new Test);
AutoPtr<Test> ptr2(ptr1);
}
{
printf("\nTesting AutoPtr detaching\n");
AutoPtr<Test> ptr1(new Test);
// We would now have a memory leak if we don't manually delete the object
Test* object = ptr1.Detach();
delete object;
}
{
printf("\nTesting AutoPtr inside a vector\n");
Vector<AutoPtr<Test> > vec;
printf("Filling vector\n");
for (size_t i = 0; i < 4; ++i)
vec.Push(new Test());
printf("Clearing vector\n");
vec.Clear();
}
{
printf("\nTesting SharedPtr\n");
SharedPtr<TestRefCounted> ptr1(new TestRefCounted);
SharedPtr<TestRefCounted> ptr2(ptr1);
printf("Number of refs: %d\n", ptr1.Refs());
}
{
printf("\nTesting WeakPtr\n");
TestRefCounted* object = new TestRefCounted;
WeakPtr<TestRefCounted> ptr1(object);
WeakPtr<TestRefCounted> ptr2(ptr1);
printf("Number of weak refs: %d expired: %d\n", ptr1.WeakRefs(), ptr1.IsExpired());
ptr2.Reset();
delete object;
printf("Number of weak refs: %d expired: %d\n", ptr1.WeakRefs(), ptr1.IsExpired());
}
{
printf("\nTesting Vector\n");
HiresTimer t;
Vector<int> vec;
SetRandomSeed(0);
for (size_t i = 0; i < NUM_ITEMS; ++i)
vec.Push(Rand());
int sum = 0;
int count = 0;
for (auto it = vec.Begin(); it != vec.End(); ++it)
{
sum += *it;
++count;
}
int usec = (int)t.ElapsedUSec();
printf("Size: %d capacity: %d\n", vec.Size(), vec.Capacity());
printf("Counted vector items %d, sum: %d\n", count, sum);
printf("Processing took %d usec\n", usec);
}
{
printf("\nTesting List\n");
HiresTimer t;
List<int> list;
SetRandomSeed(0);
for (size_t i = 0; i < NUM_ITEMS; ++i)
list.Push(Rand());
int sum = 0;
int count = 0;
for (auto it = list.Begin(); it != list.End(); ++it)
{
sum += *it;
++count;
}
int usec = (int)t.ElapsedUSec();
printf("Size: %d\n", list.Size());
printf("Counted list items %d, sum: %d\n", count, sum);
printf("Processing took %d usec\n", usec);
//.........这里部分代码省略.........