本文整理汇总了C++中CL_String::AsPtr方法的典型用法代码示例。如果您正苦于以下问题:C++ CL_String::AsPtr方法的具体用法?C++ CL_String::AsPtr怎么用?C++ CL_String::AsPtr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CL_String
的用法示例。
在下文中一共展示了CL_String::AsPtr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadObjects
void ReadObjects (const char* name)
{
CL_ObjectSequence obj_seq;
CL_BinaryFile file (name);
long i;
// Read the sequence from the file
file >> obj_seq; // Not necessarily equivalent to obj_seq.ReadFrom(file)
cout << "Contents of restored sequence:\n";
long n = obj_seq.Size();
for (i = 0; i < n; i++) {
TestClass* p = (TestClass*) obj_seq [i];
cout << p->Data().AsPtr() << endl;
}
obj_seq.DestroyContents (); // Without this, there's a memory leak!
// Read back the set
CL_StringSet aSet;
file >> aSet;
n = aSet.Size();
cout << "Restored set has " << n << " elements:\n";
CL_StringSetIterator setIter (aSet);
for (setIter.Reset (); setIter.More(); ) {
cout << setIter.Next().AsPtr() << endl;
}
// And finally, read back the maps
CL_IntPtrMap map1;
CL_StringStringMap map2; // Note that there is no builder needed for
// non-pointer-based maps
file >> map1 >> map2;
cout << "Contents of restored map1:\n";
CL_IntPtrMapIterator itr1 (map1);
CL_IntPtrAssoc assoc1;
for (itr1.Reset(); itr1.More(); ) {
assoc1 = itr1.Next ();
cout << assoc1.key << " --> " <<
((TestClass*) assoc1.value)->Data().AsPtr() << endl;
}
map1.DestroyContents ();
cout << "Contents of restored map2:\n";
// CL_StringStringMapIterator itr2 (map2);
// CL_StringStringAssoc assoc2;
// for (itr2.Reset(); itr2.More(); ) {
// assoc2 = itr2.Next ();
// printf ("'%s' --> '%s'\n", (const char*) assoc2.key,
// (const char *) assoc2.value);
// }
cout << map2 << endl;
{
CL_ObjectSequence sq;
file >> sq;
register long n = sq.Size();
cout << "sq Size: " << n << endl;
register long i;
for (i = 0; i < n; i++) {
CL_String* s = (CL_String*) sq[i];
cout << (s ? s->AsPtr() : "(NULL)") << endl;
}
delete sq[0];
delete sq[1];
}
}
示例2: f
main ()
{
// CL_StringSequence tst (18000); // Testing big sequences
CL_StringSequence a;
a.Add ("world!");
a.Add ("Hello,");
a.Add ("this is");
a.Add ("a great day.");
PrintOut (a);
a.Insert ("world! 2", 1);
PrintOut (a);
a.Insert ("Hello, 2", -1);
PrintOut (a);
a.Insert ("this is 2", 2);
PrintOut (a);
a.Insert ("a great day. 2", 3);
PrintOut (a);
a.Sort();
PrintOut (a);
#ifndef __GNUC__ // GCC Still has bugs!
CL_IntegerSet st1(2,4);
st1.Add (4);
st1.Add (7);
st1.Add (8);
st1.Add (9);
CL_StringSequence sq = a - st1;
PrintOut (sq);
#endif
a.ShiftRightAt (2);
PrintOut (a);
a[2] = "Some string here";
PrintOut (a);
a.ShiftLeftAt (2, 2);
PrintOut (a);
CL_StringSequence* b = new CL_StringSequence(10);
*b = a;
PrintOut (*b);
*b += a;
PrintOut (*b);
b->Sort();
PrintOut (*b);
CL_BinaryFile f ("seqtest.dat", TRUE);
f << *b; // Testing persistent sequences
b->MakeEmpty ();
// CL_Builder<CL_String> aBuilder;
// CL_ObjectSequence a2(0, &aBuilder);
CL_ObjectSequence a2;
CL_String* pStrg;
pStrg = new CL_String ("1"); a2.Add (pStrg);
pStrg = new CL_String ("2"); a2.Add (pStrg);
pStrg = new CL_String ("3"); a2.Add (pStrg);
pStrg = new CL_String ("10"); a2.Add (pStrg);
pStrg = new CL_String ("20"); a2.Add (pStrg);
pStrg = new CL_String ("30"); a2.Add (pStrg);
pStrg = new CL_String ("11"); a2.Add (pStrg);
pStrg = new CL_String ("22"); a2.Add (pStrg);
pStrg = new CL_String ("31"); a2.Add (pStrg);
pStrg = new CL_String ("10"); a2.Add (pStrg);
printf ("a2's size: %ld\n", a2.Size());
f << a2; // Testing persistent sequences
f.SeekToBegin();
f >> *b;
// b->ReadFrom (f);
printf ("Restored b is: \n"); PrintOut (*b);
delete b;
long i;
for (i = 0; i < a2.Size(); i++) {
printf ("'%s'\n", ((CL_String*) a2[i])->AsPtr());
}
pStrg = (CL_String*) a2.ExtractLeftmost();
printf ("Leftmost: '%s'\n", pStrg->AsPtr());
for (i = 0; i < a2.Size(); i++) {
printf ("'%s'\n", ((CL_String*) a2[i])->AsPtr());
}
delete pStrg;
pStrg = (CL_String*) a2[4];
a2.Remove (4);
delete pStrg;
for (i = 0; i < a2.Size(); i++) {
printf ("'%s'\n", ((CL_String*) a2[i])->AsPtr());
}
a2.DestroyContents ();
//.........这里部分代码省略.........