?? tptrandtptrc.cpp
字號(hào):
// TPtrAndTPtrC.cpp
//
// Copyright (c) 2005 CCNIIT. All rights reserved.
// author: hewei
// copyright 1.0
// Date: 2005-10-14
// Example shows attempt to use TPtr and TPtrC
// NOTE: the structure of this example is different to standard E32 examples
#include <e32cons.h>
// All messages written to this
LOCAL_D CConsoleBase* console;
const TInt KMAXLENGTH=20;
// Function prototypes
void callExampleL();
void doExampleL();
void useTPtr();
void useTPtrC();
//////////////////////////////////////////////////////////////////////////////
//
//use TBuf in useTBuf function
//
//////////////////////////////////////////////////////////////////////////////
void useTPtr()
{
_LIT(KNEWLINE,"\n");
_LIT(KFIRST,"hello");
_LIT(KSECOND," world!");
_LIT(KHEWEI,"hewei!");
TBufC<KMAXLENGTH> buf(KFIRST);//object of TBuf;
TPtr16 ptr(buf.Des());
// print Ptr
console->Printf(ptr);
console->Printf(KNEWLINE);
//Append another string to ptr
ptr.Append(KSECOND);
console->Printf(ptr);
console->Printf(KNEWLINE);
//Insert a string to ptr
ptr.Insert(0,KHEWEI);
console->Printf(ptr);
console->Printf(KNEWLINE);
//print length and size of ptr
_LIT(KINFO,"length=%d,size=%d\n");
console->Printf(KINFO,ptr.Length(),ptr.Size());
//left right mid
_LIT(KLEFT,"left=");
console->Printf(KLEFT);
console->Printf(ptr.Left(3));
console->Printf(KNEWLINE);
_LIT(KRIGHT,"right=");
console->Printf(KRIGHT);
console->Printf(ptr.Right(3));
console->Printf(KNEWLINE);
_LIT(KMID,"mid=");
console->Printf(KMID);
console->Printf(ptr.Mid(4));
console->Printf(KNEWLINE);
//delete
ptr.Delete(0,5);
console->Printf(ptr);
console->Printf(KNEWLINE);
}
void useTPtrC()
{
_LIT(KNEWLINE,"\n");
_LIT(KFIRST,"hello");
_LIT(KSECOND," world!");
_LIT(KHEWEI,"hewei!");
TBufC<KMAXLENGTH> bufc(KFIRST);//object of TBufC;
TPtrC ptrC(bufc);
// print TPtrC
console->Printf(ptrC);
console->Printf(KNEWLINE);
//get the modifiable description;
}
//////////////////////////////////////////////////////////////////////////////
//
// Main function called by E32
//
//////////////////////////////////////////////////////////////////////////////
GLDEF_C TInt E32Main()
{
// Get cleanup stack
CTrapCleanup* cleanup=CTrapCleanup::New();
// Some more initialization, then do the example
TRAPD(error,doExampleL());
// callExampleL() should never leave.
_LIT(KMsgPanicEpoc32ex,"EPOC32EX");
__ASSERT_ALWAYS(!error,User::Panic(KMsgPanicEpoc32ex,error));
// destroy the cleanup stack
delete cleanup;
// return
return 0;
}
//////////////////////////////////////////////////////////////////////////////
//
//
//
//////////////////////////////////////////////////////////////////////////////
void doExampleL()
{
//Get Console;
_LIT(KMsgExampleCode,"Symbian OS Example Code");
console = Console::NewL(KMsgExampleCode,TSize(KConsFullScreen,KConsFullScreen));
// Put console onto the cleanup stack.
CleanupStack::PushL(console);
int error;
TRAP(error,callExampleL());
//TRAPD(error,callExampleL());
if(error)
{
_LIT(KERROR,"error occured!\n");
console->Printf(KERROR);
}
else{
_LIT(KNOLEAVE,"No Leave!\n");
console->Printf(KNOLEAVE);
}
console->Getch();
// Remove the console object from the cleanupstack
// and destroy it.
CleanupStack::PopAndDestroy();
}
void callExampleL()
{
useTPtr();
console->Getch();
useTPtrC();
}
//////////////////////////////////////////////////////////////////////////////
//
// Do the example
//
//////////////////////////////////////////////////////////////////////////////
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -