本文整理汇总了C++中StrVec::Sort方法的典型用法代码示例。如果您正苦于以下问题:C++ StrVec::Sort方法的具体用法?C++ StrVec::Sort怎么用?C++ StrVec::Sort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StrVec
的用法示例。
在下文中一共展示了StrVec::Sort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: StrVecTest
static void StrVecTest()
{
StrVec v;
v.Append(str::Dup(_T("foo")));
v.Append(str::Dup(_T("bar")));
TCHAR *s = v.Join();
assert(v.Count() == 2);
assert(str::Eq(_T("foobar"), s));
free(s);
s = v.Join(_T(";"));
assert(v.Count() == 2);
assert(str::Eq(_T("foo;bar"), s));
free(s);
v.Append(str::Dup(_T("glee")));
s = v.Join(_T("_ _"));
assert(v.Count() == 3);
assert(str::Eq(_T("foo_ _bar_ _glee"), s));
free(s);
v.Sort();
s = v.Join();
assert(str::Eq(_T("barfooglee"), s));
free(s);
{
StrVec v2(v);
assert(str::Eq(v2.At(1), _T("foo")));
v2.Append(str::Dup(_T("nobar")));
assert(str::Eq(v2.At(3), _T("nobar")));
v2 = v;
assert(v2.Count() == 3 && v2.At(0) != v.At(0));
assert(str::Eq(v2.At(1), _T("foo")));
assert(&v2.At(2) == v2.AtPtr(2) && str::Eq(*v2.AtPtr(2), _T("glee")));
}
{
StrVec v2;
size_t count = v2.Split(_T("a,b,,c,"), _T(","));
assert(count == 5 && v2.Find(_T("c")) == 3);
assert(v2.Find(_T("")) == 2 && v2.Find(_T(""), 3) == 4 && v2.Find(_T(""), 5) == -1);
assert(v2.Find(_T("B")) == -1 && v2.FindI(_T("B")) == 1);
ScopedMem<TCHAR> joined(v2.Join(_T(";")));
assert(str::Eq(joined, _T("a;b;;c;")));
}
{
StrVec v2;
size_t count = v2.Split(_T("a,b,,c,"), _T(","), true);
assert(count == 3 && v2.Find(_T("c")) == 2);
ScopedMem<TCHAR> joined(v2.Join(_T(";")));
assert(str::Eq(joined, _T("a;b;c")));
ScopedMem<TCHAR> last(v2.Pop());
assert(v2.Count() == 2 && str::Eq(last, _T("c")));
}
}